none
Macro Help RRS feed

  • Question

  • Hi,

    I am new to VBA, and don't know much about writing macros. I am looking for some (hopefully simple) code to make things easier. Here is my situation:

    I am keeping track of annual expenses from 2018 to 2022. I have a small table of my expense categories in B3<g class="gr_ gr_110 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="110" id="110">:B10</g> and their budgeted values in C3<g class="gr_ gr_120 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="120" id="120">:C10</g>. Above, B2 says "Current Year:" and C2 says "2018". 

    In a table below, Range("B12<g class="gr_ gr_166 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="166" id="166">:G20</g>"), I am going to be compiling the annual values. The table headers are: "", 2018, 2019, 2020, 2021, and 2022. Likewise, B13<g class="gr_ gr_167 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="167" id="167">:B20</g> is the same list of expense categories from above.

    I would like the macro to copy and paste the budgeted values into their designated year on the table. Ie: Tell Excel to match C2 (2018) with C12 on the table (2018), and copy and paste values from C3<g class="gr_ gr_199 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="199" id="199">:C10</g> underneath it to C13<g class="gr_ gr_200 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style replaceWithoutSep" data-gr-id="200" id="200">:C20</g>.

    This way, if I change the date to 2019 and run the same macro it will match the correct year in the table, and paste C3<g class="gr_ gr_222 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="222" id="222">:C10</g> in D13<g class="gr_ gr_223 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style replaceWithoutSep" data-gr-id="223" id="223">:D20</g>.

    I appreciate the help!


    • Edited by AN_95 Tuesday, October 9, 2018 1:08 AM
    Tuesday, October 9, 2018 1:01 AM

All replies

  • Hi AN_95,

    >> I am new to VBA, and don't know much about writing macros. I am looking for some (hopefully simple) code to make things easier.

    You can review the sample code in the following link for reference:

    Excel VBA Copy Paste: The Complete Tutorial For Copying And Pasting Cells With Macros (And 8 Examples)

    >> I would like the macro to copy and paste the budgeted values into their designated year on the table.

    >> Tell Excel to match C2(2018) with C12(2018) on the tableand copy and paste values from C3:C10 to C13:C20

    You can try the following code to copy and paste values from C3:C10 to C13:C20:

    Sub copyMe()
    Range("C3:C10").Copy Destination:=Range("C13:C20")
    End Sub

    Hopefully it helps you.

    Best Regards,

    Yuki


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, October 10, 2018 9:37 AM
    Moderator
  • Hi AN_95,

    Thanks for your asking. Did you resolve your issue? If the post helps you, you can mark it as answer and close the post.

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

    I wish you a happy life!

    Best Regards,

    Yuki


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, October 15, 2018 7:22 AM
    Moderator