Hi guys, I'm a vba newbie and im currently having some issues writing out some vba code for this situation.
So I have a
1) Base worksheet which contains:
My base data:
Column B: different names of people
column A, C-J: other information which i pick and choose in the code below to copy
and
2) Multiple other worksheets in the same file with the names of the people:
Worksheet "Amy" contains 2 blocks of rows
- one to capture "opex" costs --> this data should start being pasted on A9 to H9
- one to capture "capex" costs (ie NOT opex) --> this data should start being pasted on A25 to H25
The code that I currently have to find the "last used row" for the 2 blocks of data works well but if theres any better way to write this, I'm all ears too! I havent been able to find any help on this because my data in column A is not continuous at all, hence the code i came up with below..
Back to the main problem..
the names in column B may not contain ALL the names of the worksheets
eg
column B contains: amy, brenda, catherine
but I have worksheets for: amy brenda catherine daphne elizabeth etc
I have already written the code to copy and paste the data for "amy" and it runs well but is there a way for this to loop for the rest of the names?
Thanks for the help!
This is the code i have now:
So I have a
1) Base worksheet which contains:
My base data:
Column B: different names of people
column A, C-J: other information which i pick and choose in the code below to copy
and
2) Multiple other worksheets in the same file with the names of the people:
Worksheet "Amy" contains 2 blocks of rows
- one to capture "opex" costs --> this data should start being pasted on A9 to H9
- one to capture "capex" costs (ie NOT opex) --> this data should start being pasted on A25 to H25
The code that I currently have to find the "last used row" for the 2 blocks of data works well but if theres any better way to write this, I'm all ears too! I havent been able to find any help on this because my data in column A is not continuous at all, hence the code i came up with below..
Back to the main problem..
the names in column B may not contain ALL the names of the worksheets
eg
column B contains: amy, brenda, catherine
but I have worksheets for: amy brenda catherine daphne elizabeth etc
I have already written the code to copy and paste the data for "amy" and it runs well but is there a way for this to loop for the rest of the names?
Thanks for the help!
This is the code i have now:
Code:
Private Sub CommandButton1_Click()
a = Worksheets("Base Sheet").Cells(Rows.Count, 1).End(xlUp).Row
For I = 2 To a
If Worksheets("Base Sheet").Cells(I, 2).Value = "Amy" And Worksheets("Base Sheet").Cells(I, 3).Value = "Opex" Then
Worksheets("Base Sheet").Range("D" & I, "J" & I).Copy
Worksheets("Amy").Activate
b = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Amy").Cells(b + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Worksheets("Base Sheet").Activate
End If
If Worksheets("Base Sheet").Cells(I, 2).Value = "Amy" And Worksheets("Base Sheet").Cells(I, 3).Value <> "Opex" Then
Worksheets("Base Sheet").Range("D" & I, "J" & I).Copy
Worksheets("Amy").Activate
c = ActiveSheet.Range("A7").End(xlDown).Row
Worksheets("Amy").Cells(c + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Worksheets("Base Sheet").Activate
End If
Next
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Base Sheet").Cells(1, 1).Select
End Sub