Hello, I need a little help.
In my source workbook I'm trying to generate rows 1(var1) and 3 (var2). Everything seems to populates correctly but at a closer glance, Var1 gets populated with a 1 and Var3 gets nothing. I have checked the target workbook to make sure that the information for Var1 and Var2 are present, and everything is there and should be populating.
Can anyone please help me? Thanks
Code:Public Sub Name_Match_Click() 'get the current workbook and sheet Set wbSource = ActiveWorkbook Set wshtSource = wbSource.Worksheets("QCTotals") 'open a external workbook Set wbTarget = Workbooks.Open("C:\WINNT\Profiles\nmayer\Desktop\learn excel\IITC Offload Master List.xls") For z = 1 To 6 If z = 1 Then Set wshtTarget = wbTarget.Worksheets("SITCO Archive") ElseIf z = 2 Then Set wshtTarget = wbTarget.Worksheets("LTI Archive") ElseIf z = 3 Then Set wshtTarget = wbTarget.Worksheets("THTI Archive") ElseIf z = 4 Then Set wshtTarget = wbTarget.Worksheets("CNI Archive") ElseIf z = 5 Then Set wshtTarget = wbTarget.Worksheets("HHT Archive") ElseIf z = 6 Then Set wshtTarget = wbTarget.Worksheets("Offload Master") End If 'get the required data and do some tricky maths with it Rowcount = wshtTarget.UsedRange.Rows.Count 'defining size of array ReDim DName(3 To Rowcount) ReDim Var1(3 To Rowcount) ReDim Var2(3 To Rowcount) ReDim SList(3 To Rowcount) '_Builds the arrays that contains all Drawing Information For x = 3 To Rowcount DName(x) = wshtTarget.Cells(x, 3).Value Var1(x) = wshtTarget.Cells(x, 1).Value Var2(x) = wshtTarget.Cells(x, 2).Value SList(x) = wshtSource.Cells(x, 2).Value Next 'set iitcqa as active workbook here For x = 3 To Rowcount For y = 3 To Rowcount If UCase(DName(x)) = UCase(SList(y)) Then wshtSource.Cells(y, 3).Value = Var1(x) wshtSource.Cells(y, 1).Value = Var2(x) y = Rowcount End If Next Next 'close the external workbook and clear up If z = 6 Then wbTarget.Close Set wshtSource = Nothing Set wbSource = Nothing Set wshtTarget = Nothing Set wbTarget = Nothing End If Next End Sub




Reply With Quote