我正在尝试用1月到12月创建一个数组,我想也有一年,所以它看起来像1月份的“J14”。我希望这能增加我跑到下一个月的所有东西,并且在12次运行后,年份将变为“J15”。我将每月运行一次这个宏,这就是为什么我想要月份并且每次运行时增加1。下面是我到目前为止,请原谅我是否错误,因为我从未使用过数组
Sub test()
Dim MyArray(1 To 12) As Integer
MyArray(1) = J
MyArray(2) = F
MyArray(3) = M
MyArray(4) = A
MyArray(5) = M
MyArray(6) = J
MyArray(7) = J
MyArray(8) = A
MyArray(9) = S
MyArray(10) = O
MyArray(11) = N
MyArray(12) = D
For i = 1 To UBound(MyArray)
Cells(i, 1).Value = MyArray(i)
Next i
End Sub
答案 0 :(得分:1)
如果你只是写" 14"这就是它的工作方式。在A13范围内。但是,正如第一条评论提出的那样,学习数据类型确实是一个好主意。此外,有很多更好的方法可以做到这一点。但仍然:
Option Explicit
Sub test()
Dim i As Long
Dim MyArray(1 To 12) As String
MyArray(1) = "J"
MyArray(2) = "F"
MyArray(3) = "M"
MyArray(4) = "A"
MyArray(5) = "M"
MyArray(6) = "J"
MyArray(7) = "J"
MyArray(8) = "A"
MyArray(9) = "S"
MyArray(10) = "O"
MyArray(11) = "N"
MyArray(12) = "D"
For i = 1 To UBound(MyArray)
Cells(i, 1).Value = MyArray(i) & Cells(13, 1)
Next i
Cells(13, 1) = Cells(13, 1) + 1
End Sub
答案 1 :(得分:0)
试试这个
Sub test()
Dim MyArray(1 To 12) As String '<--| you need to deal with "strings" (like "J"), not "integers"
MyArray(1) = "J" '<--| strings must be enclosed in quotation marks
MyArray(2) = "F"
MyArray(3) = "M"
MyArray(4) = "A"
MyArray(5) = "M"
MyArray(6) = "J"
MyArray(7) = "J"
MyArray(8) = "A"
MyArray(9) = "S"
MyArray(10) = "O"
MyArray(11) = "N"
MyArray(12) = "D"
For j= 14 To 20 '<--| set here your year range
For i = 1 To UBound(MyArray)
Cells(i, 15-j).Value = MyArray(i) & CStr(j") '<--| concatenate the month string with the year number
Next i
Next j
End Sub
答案 2 :(得分:-1)
char monthArray[] = {"J","F","M","A","M","J","J","A","S","O","N","D"};
for (int j = 00 ; j < 20 ; j ++) {
for (int i = 0; i < 12, i++) {
char month = monthArray[i];
String myNotation = "month" + j;
}
}