用两个结果variables(IF,THEN和AND)分配IF语句结果

嗯,我找不到最好的方法来做到这一点。 另外,这个代码不pipe用。 我想要“一月”(所有12个月)的文本返回两个variables:

If month = "January" Then days = "31" And monthnum = "1" End If 

build议?

终于工作的语法:

 If month = "January" Then days = 31 mon = 1 ElseIf month = "February" Then days = 29 mon = 2 'elseif for the rest of the months End If 

试试这个VBA syntext

 Dim days As Integer Dim monthnum As Integer 'if then elseif end If Month = "January" Then days = 31 monthnum = 1 ElseIf Month = "February" Then days = 28 monthnum = 2 ElseIf Month = "March" Then days = 31 monthnum = 1 ' repeat for all other months End If 

假设英文语言环境,你可以

 sMonth = "april" monthnum = month("1 " & sMonth) days = day(dateserial(2001,iif(monthnum=12, 1, monthnum+1),0)) 

你也可以使用Case语句

 Sub MonthValue() For b 1 To 20 Select Case Range("A" & a).Value Case January, March, May, June, August, October, December ActiveCell.Offset(0,1).Value = 31 Case Feburary ActiveCell.Offset(0,1).Value = 28 Case April, June, September, November ActiveCell.Offset(0,1).Value = 30 Case Else ActiveCell.Offset(0,1).Value = 0 End Select Next b End Sub