i have this test dataset:
i have it on multiple sheets, but its always different range - more columns, more rows etc. Beneath this "header" are always some blank rows.
I would like to loop throug all sheets and select this header using End(xlDown) and End(xlToRight).
I am trying to do this with the following code:
Sub WorksheetLoop()
Dim ws As Worksheet
Dim rng As Range
For Each ws In ActiveWorkbook.Worksheets
Set rng = Range("A1", Range("A1").End(xlDown).End(xlToRight))
rng.Delete
Next ws
End Sub
This macro deletes everything on first worksheet and nothing happens on any other sheet.
I tried using ws.rng but then i get an object error.
Can you please tell me what am i doing wrong?
I am studying some VBA material and trying to make changes, but i always end up with an error.
Thanks
Set rng = ws.Range("A1", ws.Range("A1").End(xlDown).End(xlToRight))
or neater isSet rng = ws.Range("A1").currentregion
. – SJRWith ws...End With
block. – BigBen