【发布时间】:2018-07-29 19:27:27
【问题描述】:
我已经包含了代码的整个标题,只是为了让我了解我有多少变量以及我在这方面有多糟糕。目前代码工作得很好!尝试在复制阶段添加 cmets。此代码不会保留大量数据,因为它会严重陷入困境。一旦引用循环,除非我制作一个新的整个页面来挖掘它,否则它就无法取回。并且 Vlookup 会经过许多单元格才能生效。
这需要一系列事件在日历上的到期日标记为 1。日历运行 28 天,然后下降到下个月开始(准确地说是 28 天)我可以让 cmets适用于第一行中的任何内容,但是当它尝试跳到第二个月时,它会出错,说未定义的变量。任何帮助,将不胜感激。
Sub Planner()
Dim data As Worksheet
Dim Cal As Worksheet
Dim C1, C2, C3, C4, C5, C6, C7, C8, C9 As Worksheet
Dim x1C, x2C, x3C, x4C, x5C, x6C, x7C, x8C, x9C As Integer
Dim y1C, y2C, y3C, y4C, y5C, y6C, y7C, y8C, y9C As Integer
Dim Cal1C, Cal2C, Cal3C, Cal4C, Cal5C, Cal6C, Cal7C, Cal8C, Cal9C As Integer
Dim a1C, a2C, a3C, a4C, a5C, a6C, a7C, a8C, a9C As Integer
Dim b1C, b2C, b3C, b4C, b5C, b6C, b7C, b8C, b9C As Integer
Dim c1c, c2c, c3c, c4c, c5c, c6c, c7c, c8c, c9c As Integer
Dim Com1C, Com2C, Com3C, Com4C, Com5C, Com6C, Com7C, Com8C, Com9C As Integer
Dim Dest1C As Range
Dim MDLDate As Integer
Set data = ThisWorkbook.Sheets("Data")
Set Cal = ThisWorkbook.Sheets("Planner")
Set C1 = ThisWorkbook.Sheets("C1")
Set C2 = ThisWorkbook.Sheets("C2")
Set C3 = ThisWorkbook.Sheets("C3")
Set C4 = ThisWorkbook.Sheets("C4")
Set C5 = ThisWorkbook.Sheets("C5")
Set C6 = ThisWorkbook.Sheets("C6")
Set C7 = ThisWorkbook.Sheets("C7")
Set C8 = ThisWorkbook.Sheets("C8")
Set C9 = ThisWorkbook.Sheets("C9")
Cal1C = C1.Range("A500").End(xlUp).Row
'sets date MDL was pulled for C2 puts on data page
data.Cells(1, 7) = C1.Cells(Cal1C, 12).Value - C2.Cells(Cal1C, 13)
For x1C = 2 To Cal1C 'x = rows y = columns
For y1C = 50 To 50
If C1.Cells(x1C, 13) < 1 Then
data.Cells(18, 8) = "X"
GoTo next1C
Else: c1c = C1.Cells(x1C, 13)
End If
a1C = Int(c1c / 28) * 24 ' gets the interval of the reference for the column address
aa1c = a1C + 8 'takes the cell address for column and offsets it to fit cal
b1C = c1c Mod 28 'get the remainder of the reference for row address
bb1c = b1C + 3 'takes the cell address for row and offsets it to fit cal
Set Dest1C = Cal.Cells(aa1c, bb1c) 'tried to set the cell output as a reference but all it equals is 1 not the address. i suspect this is part of my problem.
Com1C = C1.Cells(x1C, 8) ' this is text i want in the comment
Cal.Cells(aa1c, bb1c).Value = 1 ' this is what actually places the number on the calendar based on the cell reference. with the exception of the 1 this is where i want the comments Comm1C.
With Dest1C
.AddComment
.Comment.Text Text:=Com1C
End With
Next y1C
next1C:
Next x1C
【问题讨论】:
-
这样的声明: Dim y1C, y2C, y3C, y4C, y5C, y6C, y7C, y8C, y9C As Integer 只有最后一个是整数,其他的都是隐式变体。另外,使用 Long 而不是 Integer。 Dim y1C As Long、y2C As Long 等......
-
哪一行具体生成了错误信息,具体的错误信息是什么?
-
这样的编号变量让我觉得你应该改用数组。
-
这样的综合数据集让我可以找到
Class。和For y1C = 50 To 50和y1C没有在循环中使用? -
大部分代码都是从 Google 博士或 YouTube 教授那里学到的。我 100% 同意这是笨拙的,而不是最简化的方法。但是,嘿!有用!!!所以我很犹豫并且(老实说不够聪明,无法修复它)
标签: excel vba loops range comments