Hello,
I've written thefollowing code to look at each cell in column C of Sheet2 that equals each cellin column C of Sheet1. Sheet1 values will show up multiple times in Sheet2, soI want it to loop until either there aren't any instances of the values matchingand column G being blank, or it finds one and changes the value in column G.After it either loops through the options or fills in Sheet1 column G, itshould move on to the next row in Sheet1.
It gives me a "Next without For" error on the Next t after the first End If. But if I take that away, it doesn't seem to loop correctly through all instances of the first i before moving on.
Do I need a Do Whileloop instead of For? Something like this, perhaps? Once (t,3) and (i,3) nolonger match and i needs to increase, it ends the sub, which makes sense, butI'm not sure how to fix it without it increasing every loop. This is my firstattempt, so if it's what I need, I'll gladly take any advice you can offer.
I've written thefollowing code to look at each cell in column C of Sheet2 that equals each cellin column C of Sheet1. Sheet1 values will show up multiple times in Sheet2, soI want it to loop until either there aren't any instances of the values matchingand column G being blank, or it finds one and changes the value in column G.After it either loops through the options or fills in Sheet1 column G, itshould move on to the next row in Sheet1.
It gives me a "Next without For" error on the Next t after the first End If. But if I take that away, it doesn't seem to loop correctly through all instances of the first i before moving on.
Code:
[FONT=Calibri]Dim i As Long[/FONT]
[FONT=Calibri]Dim t As Long[/FONT]
[FONT=Calibri]Dim N As Long[/FONT]
[FONT=Calibri]Dim D As Long[/FONT]
[FONT=Calibri] [/FONT]
[FONT=Calibri]N =Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row[/FONT]
[FONT=Calibri]For i = 3 To N[/FONT]
[FONT=Calibri]D =Worksheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row[/FONT]
[FONT=Calibri]For t = 3 To D[/FONT]
[FONT=Calibri] [/FONT]
[FONT=Calibri]IfSheets("Sheet2").Cells(t, 3) = Sheets("sheet1").Cells(i, 3)Then[/FONT]
[FONT=Calibri] If Sheets("sheet2").Cells(t, 7) ="" Then[/FONT]
[FONT=Calibri] Sheets("Sheet1").Cells(i,5).Value = Sheets("sheet2").Cells(t, 8)[/FONT]
[FONT=Calibri] Exit For[/FONT]
[FONT=Calibri] End If[/FONT]
[FONT=Calibri] Next t[/FONT]
[FONT=Calibri]End If[/FONT]
[FONT=Calibri]Next i[/FONT]
[FONT=Calibri]Next t[/FONT]
Do I need a Do Whileloop instead of For? Something like this, perhaps? Once (t,3) and (i,3) nolonger match and i needs to increase, it ends the sub, which makes sense, butI'm not sure how to fix it without it increasing every loop. This is my firstattempt, so if it's what I need, I'll gladly take any advice you can offer.
Code:
[FONT=Calibri]Dim i As Integer[/FONT]
[FONT=Calibri]i = 3[/FONT]
[FONT=Calibri]Dim t As Integer[/FONT]
[FONT=Calibri]t = 3[/FONT]
[FONT=Calibri] [/FONT]
[FONT=Calibri]Do WhileWorksheets("Sheet2").Cells(t, 3) =Worksheets("Sheet2").Cells(i, 3)[/FONT]
[FONT=Calibri] If Sheets("Sheet2").Cells(t, 7) ="" Then[/FONT]
[FONT=Calibri] Worksheets("Sheet1").Cells(i,5).Value = Worksheets("Sheet2").Cells(t, 8)[/FONT]
[FONT=Calibri] End If[/FONT]
[FONT=Calibri] t = t + 1[/FONT]
[FONT=Calibri]Loop[/FONT]