簡體   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