Hello i have workbook with multiple sheets inside. I created macro that delete two columns of data(without headers) in those sheets. I used .Find
to look for the headers MEASURED VALUE
so macro will delete only data below those found headers. This is my code:
Sub Macro1()
Dim ws As Worksheet
Dim rng As Range
Dim r As Integer
Dim c As Integer
For Each ws In ThisWorkbook.Worksheets
Debug.Print ws.Name
r = ws.Range("A1").CurrentRegion.Find(what:="MEASURED VALUE", lookat:=xlWhole).Row
c = ws.Range("A1").CurrentRegion.Find(what:="MEASURED VALUE", lookat:=xlWhole).Column
Range(ws.Cells(2, c), ws.Cells(r, c).End(xlDown)).ClearContents
Next ws
End Sub
This code works it is deleting data in found columns and in every sheets. But there is a possibility that some rows will be empty. My question is how do i make code delete all the data not just data that are above the empty row. Thank you.
Try this:
Range(ws.Cells(2, c), ws.Cells(ws.Rows.Count, c).End(xlUp)).ClearContents
instead of this:
Range(ws.Cells(2, c), ws.Cells(r, c).End(xlDown)).ClearContents
Your approach could be visualised like this:
Look all the way down the column until first blank cell.
My approach, on the other hand, is like:
Go to the bottom of a column (achieved using
ws.Rows.Count
) and go up until first non-blank cell.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.