繁体   English   中英

Excel VBA中的运行时错误1004

[英]runtime error 1004 in excel vba

我是vba的新手,我不知道如何解决此问题-

运行时错误1004

并且在调试时发现num值为空。 我想在代码行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

更改此:

month = Worksheet(2).Cells(31, "J")

对此:

month = Worksheet(2).Cells(31, "J").Value

和这个:

Sheet1.Range("C" & num & ":C18") = 34

对此:

For Each c in Worksheet(1).Range("C" & num & ":C18") 
 c.Value = 34
Next c

暂无
暂无

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

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