Automatically deleting cells above and below a value

Busy N

New Member
Joined
Nov 14, 2011
Messages
45
Hi,

I need to create a formula (probably within a macro) to delete all lines above and below if the 5th line equals zero.

An example is below,

-
:20:CCT TRF P05
:23B:CRED
:32A:110809GBP5,00
:50K:/00
0
:57C://SC0
:59:/0
22
:70:0
:71A:SHA
:72:/REC/LCC-GB

Any tips or advise on how to do this would be welcomed!!
 
Do you understand the code I posted earlier?
Did you step through the code by pressing the F8 button?
Were there any questions on that code left unanswered?

Not 100%, i've never wrote a macro in my life

I've tried using the F8 button, it doesn't really tell me much
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You should organize the screens so that you see column A of your spreadsheet, and next to it the VBA screen with my macro.

Then, put cursor in the macro and hit F8. A line will become yellow. Hit F8 again, and again until you finished the macro.

Use the mouse to hover over the variables, to know their values during the execution of the macro.

This is invaluable information to understand what you're doing.
 
Upvote 0
Below is the line which is throwing it out, it is deleting the '0' but not the 'block' of 11

Columns(1).SpecialCells(2, 4).Delete xlShiftUp
 
Upvote 0
Where do you see the TRUE value in the cells?

Only in that "5th" cell or in all cells to be deleted/shifted upwards?
 
Upvote 0
Where do you see the TRUE value in the cells?

Only in that "5th" cell or in all cells to be deleted/shifted upwards?

Thanks for that, i've got it working however, i need to do a macro similar to rules to the above but it need it not to search in 1st 11 rows (the macro should start on cell A12), this time in blocks of 12, then if the 6th row equals 0 then that row and the whole block of 12 needs to be deleted.

I've tried changing the macro around but with know joy so far.

Thanks.
 
Upvote 0
Thanks for that, i've got it working however, i need to do a macro similar to rules to the above but it need it not to search in 1st 11 rows (the macro should start on cell A12), this time in blocks of 12, then if the 6th row equals 0 then that row and the whole block of 12 needs to be deleted.

I've tried changing the macro around but with know joy so far.

Thanks.

For instance:

Code:
Sub blocksofcells()

    Dim lRow As Long

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    For lRow = 18 To Range("A" & Rows.Count).End(xlUp).Row Step 12
        If Range("A" & lRow).Value = 0 Then Range("A" & lRow).Offset(-5).Resize(12).Value = True
    Next
    
    Columns(1).SpecialCells(2, 4).Delete xlShiftUp

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub

I only changed the constants from my code above, no code itself. Use F8 to step through the macro and see what happens.
 
Upvote 0
It's not finding any information in the special cells section, below is what i'm testing this on, the 1st 11 rows should stay, these rows will never need to be deleted, so in this instance i would need row 12 to row 36 to be deleted.


:20:CCT TRF P04
:23B:CRED
:32A:110809GBP4,00
:50K:/information
Information
:57C://SCInfo
:59:/Info
Information
:70:TRF P04
:71A:SHA
:72:/REC/LCC-GB
-
:20:CCT TRF P05
:23B:CRED
:32A:110809GBP5,00
:50K:/00
0
:57C://SC0
:59:/0
0
:70:0
:71A:SHA
:72:/REC/LCC-GB
-
:20:CCT TRF P06
:23B:CRED
:32A:110809GBP6,00
:50K:/00
0
:57C://SC0
:59:/0
0
:70:0
:71A:SHA
:72:/REC/LCC-GB
-
 
Upvote 0
For instance:

Code:
Sub blocksofcells()

    Dim lRow As Long

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    For lRow = 18 To Range("A" & Rows.Count).End(xlUp).Row Step 12
        If Range("A" & lRow).Value = 0 Then Range("A" & lRow).Offset(-5).Resize(12).Value = True
    Next
    
    Columns(1).SpecialCells(2, 4).Delete xlShiftUp

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub

I only changed the constants from my code above, no code itself. Use F8 to step through the macro and see what happens.


Thanks for your help it's working a treat now!!
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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