VBA LOOP "IF And Then" Criteria not Working

jacinthn

Board Regular
Joined
Jun 15, 2010
Messages
96
Ive been stuck on this for the last 2 hours, this portion of my loop isnt working.
if the value in the current worksheet cell A1 matches the master sheet column B and the value in the current sheet columns "A" matches the master sheet column A
( but i would need the most recent value or match from the master sheet returned so i think i would need to run the loop from the bottom to the top because the values in column a will be on the master sheet multiple times with different dates)
after finding the matches the loop is supposed to then return columns G,H AND I from the master sheet in columns F,G,H of the current sheet. the data is there and it just wont pull the value over from the master sheet even though column a and b of the current sheet matches the values on the master sheet.... ive mobified this code so much with no results i am stuck. please help :confused:



"sub test()
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible = True Then sht.Activate
y = 3
x = 2
Do
x = x + 1
If Range("A1") = ActiveWorkbook.Sheets("MASTER").Range("B" & x) And Range("A" & x).value = ActiveWorkbook.Sheets("MASTER").Range("A" & y). Then
Range("F" & y) = ActiveWorkbook.Sheets("MASTER").Range("G" & x).Value
Range("G" & y) = ActiveWorkbook.Sheets("MASTER").Range("H" & x).Value
Range("H" & y) = ActiveWorkbook.Sheets("MASTER").Range("I" & x).Value

y = y + 1
End If
Loop Until Sheets("MASTER").Cells(x, 1) > ""
Next sht
End sub "
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You need an ELSE in there also.

IF
THEN
ELSE
END IF

Also,

DO WHILE
LOOP

Also, use F8 in the VBA console to step through and see where it's messing up.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top