VBA help needed urgently

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hi Guys,

I have recorded the following macro
Code:
Sub Macro1()    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("C1").Select
    Range("$A$1:$C$500").AutoFilter Field:=3, Criteria1:="="
    Rows("3:3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Range("$A$1:$C$449").AutoFilter Field:=3
    Range("D2").Select
End Sub

Can I please get this to work on all the sheets in the workbook?

Thanks for your help
Asad
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I tried the following but does not work
Code:
Sub Macro1()
Dim ws As Worksheet
For Each ws In ThisWorkbook
ws.Activate
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("C1").Select
    Range("$A$1:$C$500").AutoFilter Field:=3, Criteria1:="="
    Rows("3:3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Range("$A$1:$C$449").AutoFilter Field:=3
    Range("D2").Select
Next ws
End Sub
 
Last edited:
Upvote 0
MAybe this...are you trying to delete all rows with formuas in col "C" ??
Code:
Sub Macro1()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Activate
    With Cells
    .Value = .Value
    End With
    Range("C1").Select
    Range("$A$1:$C$500").AutoFilter Field:=3, Criteria1:="="
    Rows("3:3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Range("$A$1:$C$449").AutoFilter Field:=3
    Range("D2").Select
Next ws
End Sub
 
Upvote 0
MAybe this...are you trying to delete all rows with formuas in col "C" ??

I would think the OP is trying to delete the rows/range with blank cells in column C with the criteria "=".
 
Upvote 0
Hi Mark
My assumption was looking for an "=" sign in the cell ???
I guess we'll find out when the OP responds...(y)
 
Upvote 0
Thanks a lot guys.
Yes, I am trying to delete the rows with blank cells in column C.
Orginally, the column B and D and E have formulas. But now, I need to delete the rows with no values.
 
Upvote 0
UNTESTED
Code:
Sub MM1()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Activate
  With Range("C1", Cells(Rows.Count, "C").End(xlUp))
    .Replace "", "#N/A", xlWhole, , False, , False, False
    Columns("C").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
Next ws
End Sub
 
Upvote 0
@asad, you state that "Orginally, the column B and D and E have formulas." but what about column C, is column C constants with genuine blank cells or formulas returning ""?

If it is genuine blank cells then all you probably need is...

Code:
Sub Macro2()
    Dim ws As Worksheet
    Application.ScreenUpdating = False

    For Each ws In ActiveWorkbook.Worksheets
        ws.Range("C3:C" & ws.Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(12).EntireRow.Delete
    Next

    Application.ScreenUpdating = True
End Sub

Please note that the above assumes that column A is the longest column with data.
 
Last edited:
Upvote 0
Thanks a lot guys.
I will try these solutions. As I have many files each with more than 100 tabs to be cleaned. So I have plenty of testing grounds.
I will let you all know tomorrow with the results.
Thanks
Asad
 
Upvote 0
Just in case any of the sheets don't have any blanks in column C....

Code:
Sub Macro2()
    Dim ws As Worksheet
    Application.ScreenUpdating = False

    For Each ws In ActiveWorkbook.Worksheets
    On Error Resume Next
        ws.Range("C3:C" & ws.Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(12).EntireRow.Delete
    On Error GoTo 0
    Next

    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,548
Messages
6,125,464
Members
449,229
Latest member
doherty22

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top