IF THEN NEXT macro over large range

CordingBags

New Member
Joined
Mar 7, 2022
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
I need a macro to,
IF i5=-99 THEN delete A5:C5,
then it needs to move to cell i6 and perform the same check IF i6=-99 THEN delete A6:C6.
Needs to keep repeating this line by line check until reaching i1057.

I don't expect necessarily to see the cursor moving through the sheet, just to end up with the cells in A5:C1057 deleted, if the content of their corresponding row i cells were-99.(minus 99).

Any help suggestion much appreciated.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the Board!

Do you want to just clear columns A-C, or physically delete the data, so that cells move up?
If delete, do you want to delete the WHOLE row, so all columns move up, or just columns A-C?
 
Upvote 0
No just need the colums cleared, absolutely no requirement to move cells up.
If it speeds things, the data is pre sorted. Having found the first minus 99, then all remaining rows to 1057 will also be minus 99, currently row 659 is the first but this will change up & down.
Many Thanks for your help
 
Upvote 0
Is there data in Columns D-H, and do you want the -99 in Column I to go away as well...
 
Upvote 0
Here us one way:
VBA Code:
Sub MyDeleteRows()

    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Loop through all rows
    For r = 5 To 1057
'       Clear columns A-C if column i is -99
        If Cells(r, "I").Value = -99 Then Range(Cells(r, "A"), Cells(r, "C")).ClearContents
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Here us one way:
VBA Code:
Sub MyDeleteRows()

    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Loop through all rows
    For r = 5 To 1057
'       Clear columns A-C if column i is -99
        If Cells(r, "I").Value = -99 Then Range(Cells(r, "A"), Cells(r, "C")).ClearContents
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
Works most excellently. Thanks very much
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

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