I am not an expert on VBA as I’ve recently started looking into this.
I wonder if the following is possible.
I have several workbooks with three worksheets (Old,Summary,New).
The condition is that all cells in column D with value H or M in worksheet with name New will indicate that the entire row would have to be copied to the worksheet with name Summary in the same workbook.
This mentioned above should have to happen when a button from another workbook is pressed and ideally the name of the file/workbook should be changeable so I can select what workbook do I want to run the macro.
Ideally the workbook with the data should not have any macro, all macros should be run from the second workbook with the button.
I would appreciate an example code with comments (so I can learn) if this is possible and not too complicated.
Please don’t hesitate on making any questions if something is unclear…
UPDATE
Here is the macro I manage to compose looking at different codes
Sub CopyPaste()
Set NewWorkPlan = Sheets("New Workplan")
Set NewExecSummary = Sheets("New Exec Summary")
Dim d
Dim j
d = 1
j = 2
Do Until j = 200
If NewWorkPlan.Range("D" & j) = "M" Or NewWorkPlan.Range("D" & j) = "H" Then
d = d + 1
NewExecSummary.Rows(d).Value = NewWorkPlan.Rows(j).Value
End If
j = j + 1
'MsgBox (j)
Loop
End Sub
This works perfect for me, and to take it an step forward I’d like to be able to execute this from another workbook, leaving target workbook macro free.
The problem is that the workbook I want to run the macro is going to be shared and I don’t think you can run macros.
Just change your references to the workbook you want and it should work fine (as long as the other workbook is open, though if it’s not, you can open it from code also.
Reference: