宏帮助 [英] Macro Help

查看:72
本文介绍了宏帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手,对编写宏不太了解。我正在寻找一些(希望简单的)代码,以使事情变得更容易。以下是我的情况:

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:

我正在跟踪2018年到2022年的年度开支。我在B3中有一张小费用表格< g class =" gr_ gr_110 gr-alert gr_gramm gr_inline_cards gr_run_anim样式replaceWithoutSep"数据-GR-ID =" 110" ID = QUOT; 110">:B10< / g取代;
及其在C3中的预算值< g class =" gr_ gr_120 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep"数据-GR-ID =" 120" ID = QUOT; 120">:C10< / g取代。在上面,B2表示"当前年份:"。 C2表示"2018"。 

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". 

在下表中,范围("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>"),我将编制年度值。
表格标题是: "",2018,2019,2020,2021和2022.同样,B13< g class =" gr_ gr_167 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep"数据-GR-ID =" 167" id =" 167">:B20< / g> 是
与上面相同的费用类别列表。

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.

我想要宏来复制和粘贴预算值进入他们指定的年份。即:告诉Excel将C2(2018)与表格(2018)上的C12相匹配,并复制并粘贴来自C3的值< g class =" gr_ gr_199 gr-alert gr_gramm gr_inline_cards
gr_run_anim样式replaceWithoutSep"数据-GR-ID =" 199" ID = QUOT; 199">:C10< / g取代;在它下面到C13< g class =" gr_ gr_200 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear样式replaceWithoutSep"数据-GR-ID =" 200"
id =" 200">:C20< / g>。

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>.

这样,如果我将日期更改为2019并运行相同的宏,它将匹配正确的表格中的年份,并粘贴C3< g class =" gr_ gr_222 gr-alert gr_gramm gr_inline_cards gr_run_anim样式replaceWithoutSep"数据-GR-ID =" 222" ID = QUOT; 222">:C10< / g取代; D13中的
< g class =" gr_ gr_223 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear样式replaceWithoutSep"数据-GR-ID =" 223" id =" 223">:D20< / 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>.

感谢您的帮助!

推荐答案

你好AN_95,

Hi AN_95,

>> 我是VBA的新手,对编写宏不太了解。我正在寻找一些(希望很简单的)代码来简化操作。

>> 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复制粘贴:使用宏复制和粘贴单元格的完整教程(以及8个示例)

>> 我希望宏将预算值复制并粘贴到桌面上的指定年份。

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

>>告诉Excel将C2(2018)与表中的C12(2018)匹配,并将值从C3复制并粘贴到C13:C20

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

您可以尝试使用以下代码复制和粘贴值从C3:C10到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

希望它可以帮到你。

最诚挚的问候,

Yuki


这篇关于宏帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆