Excel 中函数 month(now()) 用vba 如何表达

我要提取这个月的值,来生成生日名单,代码如下:
Sub birthdaylist()
With sheets2
End With
For i = 4 To 200
If Cells(i, 3) = "" Then
Exit Sub
Else
If Mid(Cells(i, 40), 11, 2) = Month(today()) Then
t = 9
p0 = Cells(i, 3)
With sheets1
End With
Cells(t, 5) = p0
t = t + 1
End If
End If
Next
End Sub

month(date)   '返回今日对应的月份

 

都不知道你代码 写的什么乱七八糟,

VBA 写成这样 还不如直接用公式

追答Sub brithdatlist()
 Dim rng As Range
 Set rng = Nothing
 Set sh = ThisWorkbook.Sheets("员工登记表")
  For s = 4 To sh.[d65536].End(xlUp).Row
   If Mid(sh.Cells(s, "D"), 11, 2) = Format(Date, "mm") Then
    If rng Is Nothing Then
      Set rng = sh.Cells(s, "c")
     Else
     Set rng = Union(rng, Cells(s, "c"))
     End If
    End If
   Next
  If Not (rng Is Nothing) Then rng.Copy Sheets("主页").[e9]
  Sheets("主页").[d6] = rng.Count
 End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-05-29
Month(Now())
相似回答