2015-06-16 5 views
0

Я новичок в VBA и я не знаю, как решить эту проблему проблемный найденошибка 1004 выполнения в Excel VBA

время выполнения ошибки 1004

и Num значение будет пустой отладки. Я хочу, чтобы получить значение NUM в моем коде в строке, Sheet1.Range("C" & num & ":C18")

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 

ответ

0

Изменить это:

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