Hi,
I am looking for some assistance. I have a code which takes and copies a portion of an active workbook, opens another workbook, pastes the info in the last row, closes it, and then does the same thing for another workbook. Except on the second one it is looking for a value that aligns with another cell on the main sheet and pastes the data into a separate column in that row. I have been trying multiple ways to make the for work to find the appropriate row that has the value and paste but I am continually getting different results than what I am looking to accomplish. Any assistance would be appreciated. For reference the first part works fine, its just the bottom for section I cannot get to work. You can see two versions where I am trying different ways that I can see online.
As a reference: The cell with the required match value is D5 on the main sheet (Summary) which is set to LA
The column with the lookup information is D on the Sample sheet
And I am looking to then paste the information into M through AI.
Main copy sheet = Summary
Sheet going to that is issue is Sample
Any help that can be provided would be very very appreciated. (And pardon the random things in there from me trying different ways to work and I did replace file paths with Xs due to information restrictions)
I am looking for some assistance. I have a code which takes and copies a portion of an active workbook, opens another workbook, pastes the info in the last row, closes it, and then does the same thing for another workbook. Except on the second one it is looking for a value that aligns with another cell on the main sheet and pastes the data into a separate column in that row. I have been trying multiple ways to make the for work to find the appropriate row that has the value and paste but I am continually getting different results than what I am looking to accomplish. Any assistance would be appreciated. For reference the first part works fine, its just the bottom for section I cannot get to work. You can see two versions where I am trying different ways that I can see online.
As a reference: The cell with the required match value is D5 on the main sheet (Summary) which is set to LA
The column with the lookup information is D on the Sample sheet
And I am looking to then paste the information into M through AI.
Main copy sheet = Summary
Sheet going to that is issue is Sample
Any help that can be provided would be very very appreciated. (And pardon the random things in there from me trying different ways to work and I did replace file paths with Xs due to information restrictions)
VBA Code:
Sub copytoSummary()
Dim destSht As Worksheet
Dim RNG As Range
Dim Text As Range
Dim LA As String
Dim C As Integer
Dim Cell As Range
Sheets("Summary").Range("B5:AL5").Copy
Workbooks.Open ("S:\x1") '<- at opening a workbook it becomes the active one
Set destSht = ActiveWorkbook.Worksheets("QA Sample") '<-- set the destination worksheet in the activeworkbook
With Workbooks("x1 ' <-- here should be the Sheet's name
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row ' last row in column B
.Range("B" & LastRow + 1).PasteSpecial xlValues
End With
destSht.Parent.Close True '<--| close the destination workbook, which is obtained as the Parent object of the destination worksheet
Sheets("Summary").Range("M5:AI5").Copy
LA = Range("D5")
Workbooks.Open ("x2") '<- at opening a workbook it becomes the active one
Set destSht = ActiveWorkbook.Worksheets("Sample") '<-- set the destination worksheet in the activeworkbook
With Workbooks("x3) ' <-- here should be the Sheet's name
For Each Cell In Range("D1:D80")
If Cell.Value = LA Then
LastRow = Cell.Rows.Count
.Range("M" & LastRow).PasteSpecial xlValues
Else
End If
Next
End With
' For Each C In Worksheets("Sample").Range("D1:D75").Cells
' If Cells(C, "D").Value = LA Then
' Cells(C, "M").PasteSpecial xlValues
' End If
' Next C
'End With
destSht.Parent.Close True
End Sub