Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Highlighting cell based on condition

Reply
 
Old 02-25-2009   #1 (permalink)
Codeblack


 
 

Highlighting cell based on condition

Hi all,

I have a script which will open a excel file and check whether the cell
value in Column F3 to J3 are greater than 0, if yes then those cells will be
highlighted with some color. The script works. But the problem is only the
first row is getting highlighted and then the script stops. It is not looping
through all the cells and checking for the value in the Range. Can anyone
tell me where i am doing wrong. Below is the script.



Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")
Set objWorksheet = objWorkbook.Worksheets(1)


Set objRange = objWorksheet.Range("F3:J3")

For Each objCell in objRange
Wscript.Echo objCell.Value

If IsNumeric(objCell.Value) Then
If objCell.Value > 0 Then
objCell.Interior.ColorIndex = 10
End If
End If
Next
Next
Wscript.echo "Done"


My System SpecsSystem Spec
Old 02-25-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Highlighting cell based on condition


"Codeblack" <Codeblack@xxxxxx> wrote in message
news:B18C2ECF-9BC8-4D77-A5CC-4C0DA741B53D@xxxxxx
Quote:

> Hi all,
>
> I have a script which will open a excel file and check whether the cell
> value in Column F3 to J3 are greater than 0, if yes then those cells will
> be
> highlighted with some color. The script works. But the problem is only the
> first row is getting highlighted and then the script stops. It is not
> looping
> through all the cells and checking for the value in the Range. Can anyone
> tell me where i am doing wrong. Below is the script.
>
>
>
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Visible = True
> Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")
> Set objWorksheet = objWorkbook.Worksheets(1)
>
>
> Set objRange = objWorksheet.Range("F3:J3")
>
> For Each objCell in objRange
> Wscript.Echo objCell.Value
>
> If IsNumeric(objCell.Value) Then
> If objCell.Value > 0 Then
> objCell.Interior.ColorIndex = 10
> End If
> End If
> Next
> Next
> Wscript.echo "Done"
>
Your range only covers one row. Maybe you want to use something similar to
F3:J5.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 02-25-2009   #3 (permalink)
Codeblack


 
 

Re: Highlighting cell based on condition

Thank you. This worked.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
More than one condition with the if-Statement PowerShell
Re: using xp based drive as slave on new vista based computer?? Vista installation & setup
Condition Zero and NHL 2007 Vista Games
IE 7 cannot run, DoS condition Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46