Newbie Needs Help with Simple Macro

promsi

New Member
Joined
Apr 26, 2010
Messages
14
I have a simple macro I need some help with.

I want to spin through a row range of cells (O2,X2) on a specific page. As I spin through, I want to check a specific cell in that range (S2) and see if that cell is either NULL or has a zero (0). If either is correct (NULL or 0) then delete the range and move the cells below up.

I am not familiar with the VB/Excel syntax but here is what I was starting with and obviously does not work.

Any help would be greatly appreciated.

Dim f_RowCount
f_RowCount = 275
For i = 2 To f_RowCount
f_cell1 = "0" & i
f_cell2 = "X" & i
f_checkcell = "S" & i
If IsNull(f_checkcell) Or (f_checkcell = 0) Then
Sheets("Sheet2").Select
Range(f_cell1, f_cell2).Select
Selection.Delete Shift:=x1Up
End If

Next i
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Welcome to the Board.

In what way doesn't it work? When deleting ows you need to loop backwards, otherwise some may be missed:

For i = f_RowCount To 2 Step -1
 
Upvote 0
if your macro stops at this line

Selection.Delete Shift:=x1Up

then change it to

Selection.Delete Shift:=xlUp

rest I do not have much idea on it..
 
Upvote 0
First of all the If statement that checks for NULL() is not working correctly - as I step through it it never goes into the IF statement even when the S cell is NULL

Then when I force it into the IF statement it fails at the Range("f_cell1&:&f_cell2").Select line.

It says "Run time error '1004 Method 'Range' of object '_Global' failed"
 
Upvote 0
ARG!!! - I am such an idiot - sorry to bother you for such a stupid typing error.

Ok - now to the IsEmpty problem..... Any ideas on that one?
 
Upvote 0
What's in the cell, a formula that returns ""? If so try:

If Len(f_checkcell.Value) = 0

or:

If f_checkcell.Value = ""
 
Upvote 0

Forum statistics

Threads
1,215,415
Messages
6,124,768
Members
449,187
Latest member
hermansoa

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