VBA: Find "PAGE" and delete whole row (works), but need help to do extra CONDITIONAL statement

envisioning

New Member
Joined
May 2, 2011
Messages
13
Is there a way to make this macro FIND a row with "Page" in it, then check to see if column A (one row above) is NONBLANK?



The code I am using now looks like this:
===================================




</PRE>
Code:
Sub Step1_Delete_Text_Data()
  Dim CalcMode
  Dim LastRow As Range
  Dim Row As Range
  Dim Rng As Range
  Dim Text As String
  Dim Wks As Worksheet
 
    Text = "*PAGE*"
 
    Set Wks = ThisWorkbook.Worksheets("Sheet1")
    Set Rng = Wks.Range("A1").EntireRow
 
    Set LastRow = Wks.UsedRange.Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False, False)
    If LastRow Is Nothing Then Exit Sub
    Set Rng = Rng.Resize(RowSize:=LastRow.Row + Rng.Row - 1)
 
      CalcMode = Application.Calculation
      Application.Calculation = xlCalculationManual
      Application.ScreenUpdating = False
 
        For Each Row In Rng.Rows
          If WorksheetFunction.CountIf(Row, Text) Then
             Row.Resize(RowSize:=10).EntireRow.Delete
          End If
        Next Row
 
      Application.Calculation = CalcMode
      Application.ScreenUpdating = True
 
End Sub
Is there any way for there to be a conditional IF in there too? I need it to check to see if there is a NONBLANK cell in column A, one row above the range and one row below the range.

Basically, every time there is data in the A column, it means it is a new CABLE. For the rest of my macros to work, I need each new CABLE to be separated by a blank row.

Every so many lines (in the text report), it inserts a header with a few rows of junk wording (hence the reason behind this macro to erase the 10 rows).

So, is there a way to make this macro FIND a row with "Page" in it, then check to see if column A (one row above) is NONBLANK?

If it is NONBLANK, then I would need it to check 10 rows down to see if Column A is NONBLANK.

If both conditions are TRUE, then ERASE the 10 rows, and insert a blank row.

Otherwise, just erase the 10 rows.

Again the logic:
1) find "PAGE" in a row
2) look one row up in column A to see if it is NONBLANK
3) If false, erase 10 rows
4) If TRUE, then check 10 rows down in column A to see if NONBLANK
5) If TRUE, then erase 10 rows, and insert one blank row
6) If FALSE, then erase 10 rows

Is this possible?
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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