question about a simple vba code

ccsmile

New Member
Joined
Aug 16, 2011
Messages
6
Hey, I have a question about how to write a vba program to realize such results:
I have two columns, one is the product name, another is the product price. For those rows with missing values in the second column, I need excel to color the corresponding first column with red automatically. Could u tell me how to write this simple vba code?

Hope I express the problem clearly. Thanks very much!
 
Code:
Sub ColorColumnAforMissingPricesInColumnB()
  Const DataStartRow As Long = 1
  Cells(DataStartRow, "B").Resize(Cells(Rows.Count, "A").End(xlUp).Row - DataStartRow + 1).SpecialCells(xlCellTypeBlanks).Offset(, -1).Interior.ColorIndex = 6
End Sub
Hey, thanks a lot for your anwers!
Could I ask a little bit more specific, because my data set is much complicated than I described, so I need to understand the code at first.
Could u tell me what does the first row and the second row in your code refer to?
I mean, is the first row meaning assign a constant value?
what does DataStartRow refer to?
What does End.(xlUp) mean?
A constant is like a variable except that you cannot change its value once it has been set (a variable, on the other hand, can be changed as many times as desired). The End property is the code equivalent of hitting the END key followed by one of the arrow keys. The cell it is a property of is the starting point (active cell in the keystroke equivalency) for the action. So, the starting point was specified as Cells(Rows.Count,"A")... Rows.Count is the number of rows on a worksheet (65000+ for XL2003 and earlier, 1,000,000+ for XL2007 and above), Cells(Rows.Count,"A").End(xlUp) is the same as starting from the bottom of Column A and hitting the END key followed by the Up arrow... it finds the last cell in the column with data in it.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Could I ask a little bit more specific, because my data set is much complicated than I described...
Simplifying your data structure for us is usually a bad idea as it tends to get you answers to a question you really do not care about and that, as you see, are not always easy to expand to cover your actual situation.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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