Help on setting a range

  • Thread starter Thread starter troy_lee
  • Start date Start date
T

troy_lee

Here is my code.

Dim LastRow, LastCol As Long
Dim LastCell As Range
Dim LastCellAddress As Range
Dim intNumCols As Long
Dim DataCells As Range

'Find the last row, column and last cell of the worksheet.
LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
'Set LastCell = ActiveSheet.Cells(LastRow, LastCol)

'Select from "A2" to the last cell.
Range("A2").Select
Set DataCells = Cells("A2").Resize(LastRow, LastCol).Select

I keep failing at the last line, trying to set the range variable. I
get a Type Mismatch error. I have tried everything. I don't understand
the mismatch error. DataCells is a range correct? Are my LastRow and
LastCol arguments to the Resize method good?

This should be so easy. Thanks in advance for your help.
 
I tried posting a response last night, but for some reason it didn't get
thru. Here it is again:

Hi Troy

You need Range() not Cells() in the last line, also you don't want to Select
when you are setting a range reference. Your resize needs to be modified
too, otherwise it will include an extra line at the bottom:

Set DataCells = Range("A2").Resize(LastRow - 1,LastCol)


Richard
 
Back
Top