|
-
Mar 12th, 2003, 08:23 AM
#1
vb/excel question with ranges
I have a spreadsheet and was asked to write a VB Macro that will scan the spreadsheet and change the BG color of any cells that are not filled.. IE have a vakue of ""
so i can do this easy enough i think... but i need to find the limits of the sheet.. so i figure i have to scan down and scan across to find the ends of the data.. for example the sheet looks like this
VB Code:
212.44.42.827 done done done
741.171.456.747 done done done done
123.14.4.487 done done
173.14.46.681 done done done done
113.142.46.888 done done
583.44.46.833 done done done
so only where "done" is missing i want to change the BG color... any help on this??? I don't do much excel automation.. i am not so familiar with excels methods and properties
Last edited by kleinma; Mar 12th, 2003 at 08:27 AM.
-
Mar 12th, 2003, 08:35 AM
#2
Sorted, that one didn't take too much code - not what I was expecting! btw, I'm not sure if this'll cover all cell formats, so you might wanna put another nested if statement in there checking the cell value using the isnull() function too incase that code doesn't fully cover your spreadsheet! 
Code:
Private Sub CommandButton1_Click()
For Each Cell In Range("A1:" & Cells.SpecialCells(xlCellTypeLastCell).Address)
If CStr(Trim(Cell.Value)) = "" Then
Cell.Interior.Color = &HC0FFFF
End If
Next Cell
End Sub
-
Mar 12th, 2003, 08:50 AM
#3
If you use Excel2000 or later, you can do this with no code at all, using conditional formatting.
Select the entire sheet (or the range you want to cover), and select Format --> Conditional formatting from the menu.
Make a condition like:
Cell value is
equal to
= ""
and click the Format button to set your format.
This way the sheet is updated as soon as a change is made. You don't have to run a macro anymore.
-
Mar 12th, 2003, 09:29 AM
#4
-
Mar 12th, 2003, 09:31 AM
#5
Originally posted by Frans C
If you use Excel2000 or later, you can do this with no code at all, using conditional formatting.
Select the entire sheet (or the range you want to cover), and select Format --> Conditional formatting from the menu.
Make a condition like:
Cell value is
equal to
= ""
and click the Format button to set your format.
This way the sheet is updated as soon as a change is made. You don't have to run a macro anymore.
the only reason i don't like this approach is that it will make the entire sheet the color i pick.. when i say entire sheet i mean the cells past where the fields end..
-
Mar 19th, 2003, 09:13 AM
#6
Frenzied Member
Another property that doesn't seem to get mentioned much is
This would also give you a way of selecting the correct cells.
VB Code:
For Each Cell In ActiveSheet.UsedRange.Select
If CStr(Trim(Cell.Value)) = "" Then
Cell.Interior.Color = &HC0FFFF
End If
Next Cell
Its also easier on the eye.
But each to his own.
/Andrew
-
Mar 26th, 2003, 09:14 PM
#7
Lively Member
Hi I've used the code aboove to embed in my own app
but
for this" For Each Cell " It highllight "Cell"and says "Variable not defined" What to do?y?
-
Mar 26th, 2003, 09:18 PM
#8
Lively Member
Its ok... I've declared Cell as Range and it works..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|