VB Script for excel 2010

lsein8541

New Member
Joined
Jan 23, 2011
Messages
6
Hi ! I have a 93,000 row spreadsheet, where by I want to check the cell in Column "C" for a 0. If the contents of that cell is 0 than I want to hide (or delete will work too) that entire row. So looking for some VB code that will go through a range, check the cell contacts of "C" and if 0 do the action.

Anyone know how to do that ?

If i can accomplish that, Can I also look at the contents of a different row, and if the value is a "Y" change the color of that row to any color ?

Thank you so much for any help !

Larry
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi. Try this

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = LR To 1 Step -1
    Rows(i).Hidden = Range("C" & i).Value = 0
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
1st... thank you for taking the time to help....

The macro runs with no errors, but it does not do any actions...

Thoughts ?

Thanks again
 
Upvote 0
I've just tested it on a small range and it works for me.

Do the cells in column C contain 0 or are they blank? Or perhaps they contain numbers like 0.1 formatted to zero decimal places? Or numbers stored as text?
 
Upvote 0
Woops... sorry.. user error, I move the column to "J" and didnt change it in both spots in the macro.

It works fine.. thank you...

So as long as I am asking for help...

Is there a similar VB that I can use to do two more things:

1) if Column "H" = Y than change the color of the row ?

and

2) if Column "E" = PCES-01 or PCES-02 to insert a row

Thanks again....
 
Upvote 0
Try these. Note that the first one could be done using Conditional Formatting

Code:
Sub btest()
Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = 1 To LR
    If Range("H" & i).Value = "Y" Then Rows(i).Interior.ColorIndex = 24
Next i
Application.ScreenUpdating = True
End Sub


Sub ctest()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = LR To 1 Step -1
    If Range("E" & i).Value = "PCES-01" Or Range("E" & i).Value = "PCES-02" Then Rows(i).Insert
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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