Hello all, the following code is for a uni assessment. The error "Unable to get the specialcells property of the range class" appears when i attempt to run the code, when i debug the code the debugger flags the line
"lastRow = wsSrc.Range("A:A").SpecialCells(x1CellTypeLastCell).Row" I'm attempting to find the last row on a worksheet using this code
Can any one help me solve this issue,
Thanks
Isaac
"lastRow = wsSrc.Range("A:A").SpecialCells(x1CellTypeLastCell).Row" I'm attempting to find the last row on a worksheet using this code
Can any one help me solve this issue,
Thanks
Isaac
VBA Code:
Sub CombineWorksheets()
'(Header comments)
Dim wsSrc As Worksheet
Dim wsDest As Worksheet
Dim rngDest As Range
Dim lastRow As Long
Dim destRow As Long
Set wsDest = Worksheets("Combined")
Set rngDest = wsDest.Range("A2")
Application.DisplayAlerts = False 'supress prompt for worksheet deletes
'loop through all source sheets in this workbook
For Each wsSrc In ThisWorkbook.Sheets
If wsSrc.Name <> "Combined" And wsSrc.Name <> "summary" Then 'all sheets except Combined
lastRow = wsSrc.Range("A:A").SpecialCells(x1CellTypeLastCell).Row
wsSrc.Range("Al", wsSrc.Range("I" & lastRow)).Copy Destination:=rngDest
Set rngDest = rngDest.Offset(lastRow - 1) 'update the destination range
wsSrc.Delete 'delete the source worksheet without a prompt
End If
Next
Application.DisplayAlerts = True 'turn prompts back on
End Sub