Hello,
I'm setting up a macro for a button on a worksheet, worksheet 1 in workbook X. What I would like when this button is clicked, is to check all cells in column A for the word "Copy"
Next step is that if this word is found, another workbook, Y, is opend.
Finally if the word "Copy" was found for example in cell A9, I want the data that is in cell Q9, R9 and S9, so in the same row as where the word is found, to be copied and pasted to
cells M13, P13 and S13 of workbook Y sheet 1.
For the copy part it I think it has to work with selecting with a range of something, because it has to select the cells that are in the same row as where the word "Copy" was found
I made a first start, but I'm having trouble getting it to work and don't know how I can create the copy part as it should be
Hopefully someone here can help. Thank you in advance!!
I'm setting up a macro for a button on a worksheet, worksheet 1 in workbook X. What I would like when this button is clicked, is to check all cells in column A for the word "Copy"
Next step is that if this word is found, another workbook, Y, is opend.
Finally if the word "Copy" was found for example in cell A9, I want the data that is in cell Q9, R9 and S9, so in the same row as where the word is found, to be copied and pasted to
cells M13, P13 and S13 of workbook Y sheet 1.
For the copy part it I think it has to work with selecting with a range of something, because it has to select the cells that are in the same row as where the word "Copy" was found
I made a first start, but I'm having trouble getting it to work and don't know how I can create the copy part as it should be
Hopefully someone here can help. Thank you in advance!!
Code:
Sub Copy_cells_to_Test_Report()
' Decleration
Dim x As Workbook
Dim y As Workbook
Dim row As Integer
row = 1
' Sheet name where data is
Sheets("Sheet1").Select
' Copy content if match found
If Worksheets("Sheet1").Range("A" & row) = "Copy" Then
'Open both workbooks first:
Set x = Workbooks.Open("workbookX.xlsm ")
Set y = Workbooks.Open("workbookY.xlsm ")
'Transfer values from x to y:
y.Sheets("Sheet1").Range("M13").Value = x.Sheets("Sheet1").Range("R9")
End If
End Sub
Last edited: