I have two sets of code that are working successfully thanks to Jindon & another thread but I don't know how to put them together. I am getting an error because I'm repeating the "i".
Here is the two codes:
Thank you gurus for your wisdom & constant guidance!
I am using Excel 2003.
The code is meant to:
match column A & column B data of Worksheet(WeeklyJob) to column A & column B of Worksheet(Master) then if match is found copy column C through column F into Worksheet(Master) column C through F (and overwrite any [outdated] existing data there may be in those columns [thus updating the job's weekly charges, etc.]).
If match is not found I would like it to copy entire row from Worksheet(WeeklyJobs) into first blank row at end of Worksheet(Master) (thus giving me a new record of a new job from the weekly report).
All the columns in both worksheets are labeled the same (& row 1 is headings).
(thread http://www.mrexcel.com/forum/showthread.php?p=1600311#post1600311)
Sample of my data:
Before Macro:
Worksheet(Master)
A B C D E F
Tom Jr 2 3 4 5
Tom Sr 2 3 4 5
Tom 2 3 4 5
Jen 2 3 4 5
Worksheet(WeeklyJob)
A B C D E F
Tom Sr 7 7 7 7
Xav Sr 8 8 8 8
After macro I would like it to perform/look like this:
Worksheet(Master)
A B C D E F
Tom Jr 2 3 4 5
Tom Sr 7 7 7 7
Tom 2 3 4 5
Jen 2 3 4 5
Xav Sr 8 8 8 8
Worksheet(WeeklyJob)
A B C D E F
Tom Sr 7 7 7 7
Xav Sr 8 8 8 8
Here is the two codes:
Code:
Sub testcombinetwo()
'pasted & editted from http://www.mrexcel.com/forum/showthread.php?t=99187
FinalRowSh1 = Worksheets("Master").Range("A65536").End(xlUp).Row
FinalRowSh2 = Worksheets("WeeklyJob").Range("A65536").End(xlUp).Row
For i = FinalRowSh2 To 1 Step -1
For J = FinalRowSh1 To 1 Step -1
If Worksheets("Master").Cells(J, 1) = Worksheets("WeeklyJob").Cells(i, 1) And Worksheets("Master").Cells(J, 1) = Worksheets("WeeklyJob").Cells(i, 1) Then
Worksheets("Master").Cells(J, 3) = Worksheets("WeeklyJob").Cells(i, 3)
Worksheets("Master").Cells(J, 4) = Worksheets("WeeklyJob").Cells(i, 4)
Worksheets("Master").Cells(J, 5) = Worksheets("WeeklyJob").Cells(i, 5)
Worksheets("Master").Cells(J, 6) = Worksheets("WeeklyJob").Cells(i, 6)
End If
Next J
Next i
'following portion from from jindon's reply on mrexcel
Dim a, i As Long, ii As Integer, z As String
a = Sheets("WeeklyJob").Range("a1").CurrentRegion.Resize(, 6).Value
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
z = a(i, 1) & ";" & a(i, 2)
If Not .exists(z) Then
.Add z, Array(a(i, 1), a(i, 2), a(i, 3), a(i, 4), a(i, 5), a(i, 6))
End If
Next
a = Sheets("Master").Range("a1").CurrentRegion.Resize(, 6).Value
For i = 1 To UBound(a, 1)
z = a(i, 1) & ";" & a(i, 2)
If .exists(z) Then
w = .Item(z)
For ii = 3 To 6: a(i, ii) = w(ii - 1): Next
.Remove z
End If
Next
If .Count > 0 Then
Sheets("Master").Range("a" & Rows.Count).End(xlUp)(2) _
.Resize(.Count, 6).Value = Application.Transpose(Application.Transpose(.items))
End If
End With
End Sub
I am using Excel 2003.
The code is meant to:
match column A & column B data of Worksheet(WeeklyJob) to column A & column B of Worksheet(Master) then if match is found copy column C through column F into Worksheet(Master) column C through F (and overwrite any [outdated] existing data there may be in those columns [thus updating the job's weekly charges, etc.]).
If match is not found I would like it to copy entire row from Worksheet(WeeklyJobs) into first blank row at end of Worksheet(Master) (thus giving me a new record of a new job from the weekly report).
All the columns in both worksheets are labeled the same (& row 1 is headings).
(thread http://www.mrexcel.com/forum/showthread.php?p=1600311#post1600311)
Sample of my data:
Before Macro:
Worksheet(Master)
A B C D E F
Tom Jr 2 3 4 5
Tom Sr 2 3 4 5
Tom 2 3 4 5
Jen 2 3 4 5
Worksheet(WeeklyJob)
A B C D E F
Tom Sr 7 7 7 7
Xav Sr 8 8 8 8
After macro I would like it to perform/look like this:
Worksheet(Master)
A B C D E F
Tom Jr 2 3 4 5
Tom Sr 7 7 7 7
Tom 2 3 4 5
Jen 2 3 4 5
Xav Sr 8 8 8 8
Worksheet(WeeklyJob)
A B C D E F
Tom Sr 7 7 7 7
Xav Sr 8 8 8 8