I am compiling a bunch of data from some tests ran at work, and I want to have a macro select data from the first column all the way to the last column on the sheet. The problem is that the amount of columns may be different for every file that gets entered, so I need to look for the last column while it is being graphed.
This is what I am using so far.
Columns("A:A").Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Range( _
"'" & fileType & "'!$A$1:$H$" & CStr(LastRowColH))
fileType is the name of the file, and it works fine finding it, but the problem comes when Excel auto places in the $A$1:$H$ range. I would like it to go from Column A to the last column with data in it. The last part of that line, which is CStr(LastRowColH)), is the closest thing I could find to code that finds the last part of something. If only there was a a CStr(LastColRow1)) code to get the last column instead of the last row.
Otherwise is there a way I can just set the $A$1:$H$ part equal to the active selection?
Any help would be appreciated!
Thanks
Here are a few easy ways to do this. They both assume a regular data arrangement.
Selected Range
Data Region Containing Active Cell
ActiveSheet's Used Range
Are the source data and charts on different sheets or in different workbooks? It's not really clear from the code you posted.
EDIT: or more simply just: