我正在尝试用#34; 1"来填充从D3到AH30的细胞。我在D1到AH1细胞中有日期。但我不需要用" 1"如果第一行中的相应单元格中有周末日期。
我试过下面的代码。但它的填充" 1"在包括周末日在内的所有细胞中
Function CheckWeekday_and_fill()
Dim dDate As Date
dDate = Range("D1").Value
For row = 3 To 30 ' rows for cells with date in it
For col = 4 To 34 ' cols for cells with date in it
Select Case Weekday(dDate)
Case vbSaturday, vbSunday
Cells(row, col).Value = " "
Case Else
Cells(row, col).Value = "1"
End Select
dDate = dDate + 1
Next col
Next row
End Function
答案 0 :(得分:0)
试试这个:
Function CheckWeekday_and_fill()
Dim dDate As Date
For row = 3 To 30 ' rows for cells with date in it
For col = 4 To 34 ' cols for cells with date in it
dDate = Cells(1, col).Value
Select Case Weekday(dDate)
Case vbSaturday, vbSunday
Cells(row, col).Value = " "
Case Else
Cells(row, col).Value = "1"
End Select
Next col
Next row
End Function