Can anyone explain why this happens and why it doesn't work.
(I am using Excel 2003)
I have a workbook with three worksheets. On worksheet1I have about 7000 posts. On worksheet2 about 100 posts and on worksheet 3 about 50 posts.
From Worksheet 1, if the information in column 2 is the same as the information in column2 on worksheet 2, I want to copy information (columns 4-8) to Worksheet 2 (columns 22-26) and to Worksheet 3 (Columns 22-26).
From worksheet 1 to worksheet 3 everything works perfectly well, but from Worksheet 1 to worksheet 2 it does not work. Information from worksheet 1 column 4 to worksheet 2 column 22, no problem but from 5, 6, 7,8 to columns 23,24,25,26 it does not work. The worksheets 2 and 3 are exactly the same except for the information in the columns.
Sub adressS1()
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim i As Long, j As Long
Dim LR1 As Long
Dim LR2 As Long
Dim LR3 As Long
Set ws1 = ThisWorkbook.Worksheets(1)
Set ws2 = ThisWorkbook.Worksheets(2)
Set ws3 = ThisWorkbook.Worksheets(3)
LR1 = ws1.Range("B" & Rows.Count).End(xlUp).Row
LR2 = ws2.Range("B" & Rows.Count).End(xlUp).Row
LR3 = ws3.Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LR1 - 1
For j = 2 To LR2 - 1
If ws1.Cells(i, 2) = ws2.Cells(j, 2) Then
ws2.Cells(j, 22) = ws1.Cells(i, 4)
ws2.Cells(j, 23) = ws1.Cells(i, 5)
ws2.Cells(j, 24) = ws1.Cells(i, 6)
ws2.Cells(j, 25) = ws1.Cells(i, 7)
ws2.Cells(j, 26) = ws1.Cells(i, 8)
Else
End If
Next j
Next i
End Sub
Thank you for your help
Bookmarks