Deleting Rows Based on Value of a cell, HELP!!!!

TD Rich

Active Member
Joined
Aug 10, 2010
Messages
343
Hello Excel People,

I have the following VBA code which i cant quite get to work as i want it to. What i am trying to achieve is for Excel to look at all rows that have an 'x' in column G. Then for those rows delete the cells in column A-E.

So.....

If row 5 had an 'x' in cell G5 then Excel will delete A5, B5, C5, D5 and E5.

Cheers.

TD Rich.:rolleyes:
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The code i currently have is as follows:

For i = 3000 To 1 Step -1
If Cells(i, "G") = "x" Then Range("A:E")(i).Delete
Next i
'
End Sub

this doesnt seems to work as i want it to though, any help would be greatly appreciated
 
Upvote 0
Try

Code:
For i = 3000 To 1 Step -1
    If Cells(i, "G").Value = "x" Then Range("A" & i).Resize(,5).Delete shift:=xlShiftUp
Next i
 
Upvote 0
VoG / Jonmo1

Cheers for that Guys, big help!!!!!!! Now i can go back to sleep! :eeek:

Thanks,

TD Rich
 
Upvote 0
Hello Jonmo1,

Got a follow up question on that. I have a formula in columns G & H which referance column A. When i delete column A using the coding you guys provided i am left with a #REF! referance in the cells containg the formula that referanced cloumn A. Is there anyway of removing the data in the cells but still allowing the formula in Columns G&H to referance column A?

Alternatively, is it possible to referance the relevent cells in columns G&H and rewrite the formula in as part of a macro?

Cheers,

TD Rich.
 
Upvote 0
I am almost there code i have now is as follows:

For i = 3000 To 1 Step -1
If Cells(i, "G").Value = "x" Then Range("A" & i).Resize(, 5).Delete shift:=xlShiftUp
Range("E" & i).FormulaR1C1 = "=IF(RC[-4]>1,""yes"",""no"")"
Next i
End Sub


This does what i want but then copies the formula into every cell in column E. What i need is it to only copy the formula to the Cell in column E that is in the row that has had cells A- E deleted
 
Upvote 0
I am almost there code i have now is as follows:

This does what i want but then copies the formula into every cell in column E. What i need is it to only copy the formula to the Cell in column E that is in the row that has had cells A- E deleted

Just have to rearrange the IF a little bit

Code:
For i = 3000 To 1 Step -1
If Cells(i, "G").Value = "x" Then 
    Range("A" & i).Resize(, 5).Delete shift:=xlShiftUp
    Range("E" & i).FormulaR1C1 = "=IF(RC[-4]>1,""yes"",""no"")"
End If
Next i
End Sub

Hope that helps..
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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