Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA - Cell Formatting

Status
Not open for further replies.

davisto01

MIS
Jul 11, 2003
21
US
Looking for a little syntax help.

I'm writing an excel module that will scan each cell for a date. If the date is not equal to today's date then I would like to highlight the entire row grey.

So far I was thinking something along the lines of the follwing:
Because this is my first time doing vba (I was a java programmer) I will have to use psuedo code.

Sub todayStandsOut()
If Sheet1.(Range("Current Cell")) != date(today) Then
Rows("current row").Interior.ColorIndex = 15
End If
End Sub

Please help!
Also If anyone knows an excel vba command reference site or listing that would be helpful as well.

Thanks
 
Davisto01
Skip's suggestion will work perfectly well but if you want to code, your pseudocode was nearly there

dim lRow as long, wCol as integer
'Get column to check in
wCol = inputbox("Enter Column Number to check")
'Get last used cell in that column
lRow = cells(65536,wCol).end(xlup).row

For i = 2 to lRow 'assumes headers in row 1
if format(cells(i,wCol).value,&quot;dd/mm/yy&quot;)<>format(Now(),&quot;dd/mm/yy&quot;) then rows(i).entirerow.interior.colorindex = 15
next i

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Davisto01,

Here's another option. Depending on your application (i.e. number of records, and your actual objective), you might want to consider using Excel's &quot;Advanced Filter&quot;.

Using this option, you could have two macro buttons...

One button to &quot;filter-in-place&quot; the records that do not have the current date - so that all the user views are those records.

The other button will be for &quot;Showing all records&quot;.

Yet another option is to use the Advanced Filter to extract the records to a SEPARATE sheet - where you could use as a &quot;template&quot; sheet (i.e. pre-set with print settings) from which you can first view the records, and/or print them. This can be attached to a 3rd button.

I've created an example file based on the above. If you'd like the file, just email me and I'll send the file by return email.

Hope this helps.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top