Sparda142

Board Regular
Joined
Dec 19, 2018
Messages
52
Hello,

I'm new to VBA and need some help. Im bascially trying to say - look in column C, if the value is "State ID" then clear contents


Sub ClearRowWith_ID()
Last = Cells(Rows.Count, "C").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "C").Value) = "State ID" Then

End If
Next i
End Sub


<tbody>
</tbody>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
No need for a loop.
Code:
Sub Sparda142()
   Range("C:C").Replace "State ID", "", xlWhole, , False, , False, False
End Sub
 
Upvote 0
Try:
Code:
[TABLE="class: cms_table"]
<tbody>[TR]
[TD]Sub ClearRowWith_ID()

Last = Cells(Rows.Count, "C").End(xlUp).Row
For i = 1 to Last
    If Cells(i, "C").Value = "State ID" Then Cells(i, "C").ClearContents   
Next i

End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Note that you do not have to iterate threw the rows backwards if you are just clearing cells and not deleting rows.


EDIT: Fluff's way is more efficient/faster, as it does not use loops.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

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