I would like to select all the contiguous cells in a sales report dump.
The report is a set number of columns (31). Although I would like to build a bit of variability into my code to accommodate a change in the number of columns.
The number of rows changes each week, sometimes less, sometimes more. It always starts at cell [A4
].
I though of using COUNTA
function to count used number of rows, then set that as a variable. Similar with rows.
I get
Run-time Error '1004': Method 'Range' of object'_Global failed
For me the key is to learn VBA using task I need getting done. I understand the logic behind my code. If some proposes a totally different code I might get lost.
But I am open minded.
Sub ReportArea()
Dim numofrows As Integer
Dim numofcols As Integer
Dim mylastcell As String
Dim myrange As Range
Worksheets("Sheet1").Select
numofrows = WorksheetFunction.CountA(Range("AE:AE"))
numofcols = WorksheetFunction.CountA(Range("4:4"))
Set myrange = Range(Cells(4, 1), Cells(numofrows, numofcols))
Range(myrange).Select
End Sub