Hi everyone. I am really new to Excel VBA and I am trying to automate some processes at work.
Before we push out our products, I use workbook A (Source & the active workbook) to generate charts based on bloomberg data and given parameters which are keyed in. These parameters are keyed into specific cells. IF the products are pushed out, the parameters need to be keyed in accordingly in another workbook B (Destination & the tracker workbook). Workbook B takes those parameters and tracks the changes in the asset prices in bloomberg.
1) C5 from workbook A needs to be pasted into the last empty cell in the column A (A97 now) in workbook B
2) C16 from workbook A needs to be pasted into the last empty cell in column C (C97 now) in workbook B
3) C10 from workbook A needs to be pasted into the last empty cell in the column D (D97 now) in workbook B
4) C8 from workbook A needs to be pasted into the last empty cell in the column F (F97 now) in workbook B
5) C7 from workbook A needs to be pasted into the last empty cell in the column H (H97 now) in workbook B
I did a trial to execute the first action and here is my code.
Somehow, the code gives me an object defined error 1004. I may be using the variables incorrectly. I would really love to automate those 5 steps as it would save me and my team a lot of time. I would really appreciate any help that you guys can provide! Thank you.
Before we push out our products, I use workbook A (Source & the active workbook) to generate charts based on bloomberg data and given parameters which are keyed in. These parameters are keyed into specific cells. IF the products are pushed out, the parameters need to be keyed in accordingly in another workbook B (Destination & the tracker workbook). Workbook B takes those parameters and tracks the changes in the asset prices in bloomberg.
1) C5 from workbook A needs to be pasted into the last empty cell in the column A (A97 now) in workbook B
2) C16 from workbook A needs to be pasted into the last empty cell in column C (C97 now) in workbook B
3) C10 from workbook A needs to be pasted into the last empty cell in the column D (D97 now) in workbook B
4) C8 from workbook A needs to be pasted into the last empty cell in the column F (F97 now) in workbook B
5) C7 from workbook A needs to be pasted into the last empty cell in the column H (H97 now) in workbook B
I did a trial to execute the first action and here is my code.
Code:
[HR][/HR][I]
Sub CopyPasteForTracker2017Q2()[/I]
[I]Dim TrackerBook As Workbook[/I]
[I]Dim CLastFundRow As Integer[/I]
[I]Dim CFirstBlankRow As Integer[/I]
[I]Dim wksSource As Worksheet, wksDest As Worksheet[/I]
[I]Dim rngStart As Range, rngDest As Range[/I]
[I]Dim SourceCell As Range[/I]
[I]'## Open both workbooks first:[/I]
[I]Set TrackerBook = Workbooks.Open(" F:\PB Mktg\Bloomberg\bloomberg13\TEST Product Ideas Performance Tracking Q2-17.xlsx ")[/I]
[I]Set wksDest = TrackerBook.Sheets("KOELN (Intra-day)")[/I]
[I]Set wksSource = ActiveWorkbook.Sheets("KO-ELN")[/I]
[I]'Finds last row of content[/I]
[I] CLastFundRow = wksDest.Range("A1").End(xlDown).Row[/I]
[I]'Finds first row without content[/I]
[I] CFirstBlankRow = CLastFundRow + 1[/I]
[I]'Copy Data[/I]
[I] Set SourceCell = wksSource.Cells("C5")[/I]
[I] SourceCell.Copy[/I]
[I]'Paste Data Values[/I]
[I] Set rngDest = wksDest.Cells("A1" & CLastBlankRow)[/I]
[I] rngDest.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False[/I]
[I]End Sub
[/I][HR][/HR]
Somehow, the code gives me an object defined error 1004. I may be using the variables incorrectly. I would really love to automate those 5 steps as it would save me and my team a lot of time. I would really appreciate any help that you guys can provide! Thank you.
Last edited by a moderator: