Hi Excel Community!
I'm having trouble with the following code for a day now. If someone could kindly help this would be great, thank you!
Basically I have a data range and there is some unnecessary data under the last row in the data set.
I have data in the cell range A1:F7 for example, and there is a consistent gap under column A:A under the last row. So I have used this as my unique identifier for the code.
But the code only works to delete a specific range based on the worksheet I have selected.
But I need it to loop through the worksheets and delete the data since the data in the different sheets have different row lengths. For example, the next sheet has data in the range A1:F20.
My code includes 'unmerge' because some cells are merged so I unmerge first before running the VBA.
If anyone has any ideas, this would be fantastic! Thank you
Best regards
I'm having trouble with the following code for a day now. If someone could kindly help this would be great, thank you!
Basically I have a data range and there is some unnecessary data under the last row in the data set.
I have data in the cell range A1:F7 for example, and there is a consistent gap under column A:A under the last row. So I have used this as my unique identifier for the code.
But the code only works to delete a specific range based on the worksheet I have selected.
But I need it to loop through the worksheets and delete the data since the data in the different sheets have different row lengths. For example, the next sheet has data in the range A1:F20.
VBA Code:
Sub ClearRows()
Const NumOfRowClear = 100
Dim r As Range, lastrow As Long, ws As Worksheet
lastrow = ActiveSheet.Range("A1").End(xlDown).Row
For Each ws In ActiveWorkbook.Worksheets
Cells.UnMerge
Set r = ws.Range(ws.Cells(lastrow + 1, 1), ws.Cells(lastrow + NumOfRowClear, 10000))
r.ClearContents
Next ws
End Sub
My code includes 'unmerge' because some cells are merged so I unmerge first before running the VBA.
If anyone has any ideas, this would be fantastic! Thank you
Best regards