gpt4 book ai didi

VBA:如果单元格格式是日期,那么做一些事情

转载 作者:行者123 更新时间:2023-12-04 22:00:27 24 4
gpt4 key购买 nike

我在为宏设置条件时遇到问题。
它应该这样做:
If CELL_A is * **AND** CELL_B is **DATE** then....

    Sub kontrolafyzprav()

radek = 4

With List1

Do While .Cells(radek, 3) <> ""
If .Cells(radek, 3) = "DOM" And .Cells(radek, 7).NumberFormat = "General" Then
.Cells(radek, 3).Interior.Color = RGB(255, 150, 150)
.Cells(radek, 7).Interior.Color = RGB(255, 150, 150)

ElseIf .Cells(radek, 3) = "MO" And .Cells(radek, 7).NumberFormat = "d/m/yyyy" Then
.Cells(radek, 3).Interior.Color = RGB(255, 150, 150)
.Cells(radek, 7).Interior.Color = RGB(255, 150, 150)
' :( :( :( :(

End If
radek = radek + 1
Loop

End With

End Sub

符合 ElseIf .Cells(radek, 3) = "MO" And .Cells(radek, 7).NumberFormat = "d/m/yyyy" Then我尝试了我能想到的一切。

第一组条件很好,但我无法获得第二组:/

有什么帮助吗?

最佳答案

原生 VBA IsDate Function很好地确定单元格的内容以查看它是否包含日期。 Range.Value property 保留的区域特定日期设置(但不是 Range.Value2 property )有助于做出决定。

Sub kontrolafyzprav()
Dim raek As Long

radek = 4

With List1
Do While .Cells(radek, 3) <> ""
If .Cells(radek, 3) = "DOM" And .Cells(radek, 7).NumberFormat = "General" Then
.Cells(radek, 3).Interior.Color = RGB(255, 150, 150)
.Cells(radek, 7).Interior.Color = RGB(255, 150, 150)

ElseIf .Cells(radek, 3) = "MO" And IsDate(.Cells(radek, 7)) Then
.Cells(radek, 3).Interior.Color = RGB(255, 150, 150)
.Cells(radek, 7).Interior.Color = RGB(255, 150, 150)
' :( :( :( :(
End If
radek = radek + 1
Loop
End With

End Sub

IsDate 函数不会被看起来像日期的无效文本所迷惑。

关于VBA:如果单元格格式是日期,那么做一些事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35923204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com