Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...