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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Ok - so that solved that problem - now when I try to perform the Delete function is says

Delete Method of Range Class failed

I tried changing the "1" to a "|" as suggested by RAVI4EVER but it said "Invalid Character"

Here is the latest code based on changes:

Dim f_RowCount
f_RowCount = 275
For i = f_RowCount To 2 Step -1
f_cell1 = "O" & i
f_cell2 = "X" & i
Set f_checkcell = Range("S" & i)
Sheets("Sheet2").Select
Range(f_cell1 & ":" & f_cell2).Select
If Len(f_checkcell.Value) = 0 Or f_checkcell = 0 Then
Selection.Delete Shift:=x1Up
End If

Next i
 
Upvote 0
Thank you VERY much for your patience with me and your incredibly quick response.

All works now.
 
Upvote 0

Forum statistics

Threads
1,216,737
Messages
6,132,436
Members
449,727
Latest member
Aby2024

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