Hi,
My file has multiple sheets. The goal is to find an exact match in column C of sheet 4 to column M of sheet 1, sheet 2 and sheet 3.
Edit: Code formatting
Image of sheet 1:
Image of sheet 2:
Image of sheet 3:
Image of sheet 4:
Image of desired sheet 4 outcome:
In theory, what I am trying to do is if X = Y, then X = Z.
For example, if we are working with cell C2 in sheet 4, where C2 = 107028. I want to find which row in sheet 1 M contains 107028. When a row from column M of sheet 1 = 107028, I want to take the data from that row in columns D:K of that row and make them the values for columns D:K in sheet 4 in the row that 107028 is on.
This process repeats for sheets 2 and 3. Find exact matches in sheet 2 row M to sheet 4 row C and subsequently sheet 3 row M value to sheet 4 row C.
I have attempted to loop through the sheet of "Print_Stats" (sheet 1 in my post's case), "Email_Stats" (sheet 2 in my post's case), and "Link_Stats" (sheet 3 in my posts case) into "Combined_Stats" (which in our case is sheet 4):
Code:
Sub Combine_Stats ()
'attempted loop
Dim p_id As Integer
Dim l_id As Integer
Dim e_id As Integer
Dim c_id As String
Dim i As Long
'get the number of the last row with data in all four sheets
lastRowcombined = Worksheets("Combined_Stats").Cells(Rows.Count, "C").End(xlUp).Row
lastRowprint = Worksheets("Print_Stats").Cells(Rows.Count, "M").End(xlUp).Row
lastRowemail = Worksheets("Email_Stats").Cells(Rows.Count, "M").End(xlUp).Row
LastRowlink = Worksheets("Link_Stats").Cells(Rows.Count, "M").End(xlUp).Row
'for every value in column M of From Print_Stats trying to find when the p_id = the c_id from column C in Combined_Stats sheet
For i = 1 To lastRowprint
If Worksheets("Print_Stats").Cells(i, "M").Value = Worksheets("Combined_Stats").Cells(i,"C").Value Then
Worksheets("Print_Stats").Range(Cells(i, "M")).Copy
Worksheets("Combined_Stats").Range("C" & lastRowcombined).PasteSpecial xlPasteValues
End If
Next
'for every value in column M of From Email_Stats trying to find when the p_id = the c_id from column C in Combined_Stats sheet. Pasting values to next available column
For i = 1 To lastRowemail
If Worksheets("Email_Stats").Cells(i, "M").Value = Worksheets("Combined_Stats").Cells(i,"C").Value Then
Worksheets("Email_Stats").Range(Cells(i, "M")).Copy
Worksheets("Combined_Stats").Range("C" & lastRowcombined).PasteSpecial xlPasteValues
End If
Next
'for every value in column M of From Link_Stats trying to find when the p_id = the c_id from column C in Combined_Stats sheet. Pasting values to next available column
For i = 1 To LastRowlink
If Worksheets("Link_Stats").Cells(i, "M").Value = Worksheets("Combined_Stats").Cells(i,"C").Value Then
Worksheets("Link_Stats").Range(Cells(i, "M")).Copy
Worksheets("Combined_Stats").Range("C" & lastRowcombined).PasteSpecial xlPasteValues
End If
Next
End Sub
My file has multiple sheets. The goal is to find an exact match in column C of sheet 4 to column M of sheet 1, sheet 2 and sheet 3.
Edit: Code formatting
Image of sheet 1:
Image of sheet 2:
Image of sheet 3:
Image of sheet 4:
Image of desired sheet 4 outcome:
In theory, what I am trying to do is if X = Y, then X = Z.
For example, if we are working with cell C2 in sheet 4, where C2 = 107028. I want to find which row in sheet 1 M contains 107028. When a row from column M of sheet 1 = 107028, I want to take the data from that row in columns D:K of that row and make them the values for columns D:K in sheet 4 in the row that 107028 is on.
This process repeats for sheets 2 and 3. Find exact matches in sheet 2 row M to sheet 4 row C and subsequently sheet 3 row M value to sheet 4 row C.
I have attempted to loop through the sheet of "Print_Stats" (sheet 1 in my post's case), "Email_Stats" (sheet 2 in my post's case), and "Link_Stats" (sheet 3 in my posts case) into "Combined_Stats" (which in our case is sheet 4):
Code:
Sub Combine_Stats ()
'attempted loop
Dim p_id As Integer
Dim l_id As Integer
Dim e_id As Integer
Dim c_id As String
Dim i As Long
'get the number of the last row with data in all four sheets
lastRowcombined = Worksheets("Combined_Stats").Cells(Rows.Count, "C").End(xlUp).Row
lastRowprint = Worksheets("Print_Stats").Cells(Rows.Count, "M").End(xlUp).Row
lastRowemail = Worksheets("Email_Stats").Cells(Rows.Count, "M").End(xlUp).Row
LastRowlink = Worksheets("Link_Stats").Cells(Rows.Count, "M").End(xlUp).Row
'for every value in column M of From Print_Stats trying to find when the p_id = the c_id from column C in Combined_Stats sheet
For i = 1 To lastRowprint
If Worksheets("Print_Stats").Cells(i, "M").Value = Worksheets("Combined_Stats").Cells(i,"C").Value Then
Worksheets("Print_Stats").Range(Cells(i, "M")).Copy
Worksheets("Combined_Stats").Range("C" & lastRowcombined).PasteSpecial xlPasteValues
End If
Next
'for every value in column M of From Email_Stats trying to find when the p_id = the c_id from column C in Combined_Stats sheet. Pasting values to next available column
For i = 1 To lastRowemail
If Worksheets("Email_Stats").Cells(i, "M").Value = Worksheets("Combined_Stats").Cells(i,"C").Value Then
Worksheets("Email_Stats").Range(Cells(i, "M")).Copy
Worksheets("Combined_Stats").Range("C" & lastRowcombined).PasteSpecial xlPasteValues
End If
Next
'for every value in column M of From Link_Stats trying to find when the p_id = the c_id from column C in Combined_Stats sheet. Pasting values to next available column
For i = 1 To LastRowlink
If Worksheets("Link_Stats").Cells(i, "M").Value = Worksheets("Combined_Stats").Cells(i,"C").Value Then
Worksheets("Link_Stats").Range(Cells(i, "M")).Copy
Worksheets("Combined_Stats").Range("C" & lastRowcombined).PasteSpecial xlPasteValues
End If
Next
End Sub