Jump to content

Excel VBscript question


Recommended Posts

Hey guys,

trying to expand my vb knowledge, thought i would start with easy task, just reading 2 columns on excel and comparing the values of one column to the other and look for the same values and highlight those cells,

running into issues with the nest DO loops.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
("<file>")


dim approved(70)
dim Current(70)

Dim y
Dim x

intRow = 2
intRowy = 2
Do Until objExcel.Cells(intRow,1).Value = ""
approved(x) = objExcel.Cells(intRow,1).value
Do Until objExcel.Cells(intRowy,2).Value = ""
Current(y) = objExcel.Cells(intRowy,2).value
If current(y) = approved(x) Then
objExcel.Cells(intRow,1).Interior.ColorIndex = 46
objExcel.Cells(intRowy,2).Interior.ColorIndex = 46
msgbox "approved x: " & approved(x)
msgbox "current y: " & Current(y)
intRowy = intRowy + 1
y = y + 1

else
intRowy = intRowy + 1
y = y + 1

End if
Loop

msgbox "test"
intRow = intRow + 1
x = x +1
'msgbox approved(x)
'msgbox current(y)


Loop


objExcel.Quit

is it current form, it will cell 1 on column one, then get cell 1 in column 2, will compare the 2 but then won't restart the second loop, on the end if statement it will kick you out of the nested do loop, should it do this? in a non nested loop this does not happen.

thoughts?

Link to comment
Share on other sites


After you exit the second loop after reachint the end of the list you need to reset it back to the top of the list.

The way it is written now the second time through it is already at the end of the list on a blank cell so the Do Until statement is already true.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...