vba - Type Mismatch Error - charting data -


sub button2_click()  dim lastrow long dim xtitle range dim xdata range dim ycolumn long dim ytitle range dim ydata range dim graphrange range   'find last row data lastrow = activesheet.cells(activesheet.rows.count, "a").end(xlup).row  'set x-axis title , data set xtitle = range("a1") set xdata = range("a2" & lastrow)    'find cap, set y-axis title  = range("b1")   'set y-axis data **ydata = range("b2" & lastrow)**  'set total graph range set graphrange = union(xtitle, xdata, ytitle, ydata)  'create chart  activesheet.shapes.addchart.select  activechart.charttype = xlxyscatter  activechart.setsourcedata source:=graphrange  activechart.location where:=xllocationasnewsheet  activechart.setelement (msoelementlegendnone)  activechart.charttitle.text = "mm index"  activechart.setelement (msoelementprimarycategoryaxistitleadjacenttoaxis)  selection.caption = xtitle  activechart.setelement (msoelementprimaryvalueaxistitlerotated)  selection.caption = ytitle  application.screenupdating = true    end sub 

hi, trying chart range of data x axis coming col , y axis b. can not stop getting compile error type mismatch. can please explain causing error , how avoid it.

thank you.

your xdata , ydata not set properly. replace

set xdata = range("a2" & lastrow)  set ydata = range("b2" & lastrow) 

by

set xdata = range("a2:a" & lastrow) set ydata = range("b2:b" & lastrow) 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -