[英]runtime error 1004 in excel vba
I am new to vba and I do not know how to solve this issue- 我是vba的新手,我不知道如何解决此问题-
run time error 1004 运行时错误1004
and num value is found to be empty on debugging. 并且在调试时发现num值为空。 I want to get the num value in my code in the line, Sheet1.Range("C" & num & ":C18")
我想在代码行Sheet1.Range("C" & num & ":C18")
获取num值
Enum MonthOfYear
April = 7
May = 8
June = 9
July = 10
August = 11
September = 12
October = 13
November = 14
December = 15
January = 16
February = 17
March = 18
End Enum
Private Sub GenerateTDS_Click()
Dim month As String
month = Sheet2.Cells(31, "J")
num = myfunction(month)
Sheet1.Range("C" & num & ":C18") = 34
End Sub
Function myfunction(month)
If (month = "April") Then
myfunction MonthOfYear.April
End If
If (month = "May") Then
myfunction MonthOfYear.May
End If
If (month = "June") Then
myfunction MonthOfYear.June
End If
If (month = "July") Then
myfunction MonthOfYear.July
End If
If (month = "August") Then
myfunction MonthOfYear.August
End If
If (month = "September") Then
myfunction MonthOfYear.September
End If
If (month = "October") Then
myfunction MonthOfYear.October
End If
If (month = "November") Then
myfunction MonthOfYear.November
End If
If (month = "December") Then
myfunction MonthOfYear.December
End If
If (month = "January") Then
myfunction MonthOfYear.January
End If
If (month = "February") Then
myfunction MonthOfYear.February
End If
If (month = "March") Then
myfunction MonthOfYear.March
End If
End Function
Change this: 更改此:
month = Worksheet(2).Cells(31, "J")
to this: 对此:
month = Worksheet(2).Cells(31, "J").Value
And this: 和这个:
Sheet1.Range("C" & num & ":C18") = 34
To this: 对此:
For Each c in Worksheet(1).Range("C" & num & ":C18")
c.Value = 34
Next c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.