简体   繁体   English

根据其他几个单元格 (VBA) 的值向 Excel 中的单元格添加注释

[英]Adding a note to a cell in Excel based on the values of several other cells (VBA)

I wish to use VBA to add a note to a cell.我希望使用 VBA 向单元格添加注释。 This note should be the cell values from a different tab.此注释应该是来自不同选项卡的单元格值。

I have the tab - Current Total Breakdown.我有选项卡 - 当前总细分。 I wish to copy cells H5 and H6 in this tab into the note on cell K5 on the Monthly Totals tab.我希望将此选项卡中的单元格 H5 和 H6 复制到“每月总计”选项卡上的单元格 K5 上的注释中。 I would also like the cell value in H5 to be on one line and the value of H6 on another line.我还希望 H5 中的单元格值在一行上,而 H6 中的值在另一行上。

For example, if H5 and H6 in the Current Total breakdown tab are equal to "Hi x 10" and "Hello x 20" respectively:例如,如果当前总计细分选项卡中的 H5 和 H6 分别等于“Hi x 10”和“Hello x 20”:

I would like K5 in Monthly Totals to have a comment saying:我希望每月总计中的 K5 发表评论说:

Hi x 10
Hello x 20

as shown one below the other so i know they're from different cells.如下图所示,所以我知道它们来自不同的细胞。

I have to repeat this too.我也得重复一遍。 I know how to write I'm not very good with VBA but I know how to write the select, copy and paste and even add a note to a cell but not in the format I wish like above.我知道如何写我对 VBA 不是很好,但我知道如何写选择、复制和粘贴,甚至向单元格添加注释,但不是我希望的格式。

Not really sure at all how I would go about this so would greatly appreciate and help and if you could break the code down for me so I can edit it for my other ranges I need to apply it.完全不确定我将如何处理此问题,因此将不胜感激和帮助,如果您可以为我分解代码,以便我可以为我需要应用的其他范围编辑它。

Code i've got so far (tried to record the macro; not 100% sure what the last line is doing).到目前为止我得到的代码(试图记录宏;不是 100% 确定最后一行在做什么)。

Sheets("Current Total breakdown").Select
Range("H5").Select
Selection.Copy
Sheets("Monthly Totals").Select
ActiveCell.Offset(-19, 8).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.AddComment
ActiveCell.Comment.Visible = False
ActiveCell.Comment.Text Text:=Chr(10) & "" & Chr(10) & ""
ActiveCell.Offset(16, -6).Range("A1").Select 

No need to select anything:无需选择任何内容:

Dim myComment as String
myComment = Sheets("Current Total breakdown").Range("H5").value & Chr(10) & Sheets("Current Total breakdown").Range("H6").Value
Sheets("Monthly Totals").Range("K5").AddComment.Text myComment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM