Friday, December 25, 2015

About Date on Cell VBA

Example1

1
2
3
Sub Button1_Click()
    MsgBox Range("B2").Value
End Sub


Example2

1
2
3
Sub Button2_Click()
    MsgBox Range("B9").Value & vbCrLf & Range("B9").Text
End Sub

Example3

1
2
3
Sub Button3_Click()
    MsgBox Range("B16").Value2 & vbCrLf & Range("B16").Text
End Sub
Example4

1
2
3
4
5
6
7
8
9
Sub Button4_Click()
    Dim FoundCell As Range
    Set FoundCell = Range("B25:B40").Find(What:="12/31/2015")
    If FoundCell Is Nothing Then
        MsgBox "Not Found"
    Else
        MsgBox FoundCell.Offset(0, 1)
    End If
End Sub

Example5
Below code will give output Not Found

1
2
3
4
5
6
7
8
9
Sub Button5_Click()
    Dim FoundCell As Range
    Set FoundCell = Range("B44:B59").Find(What:="12/31/2015", LookIn:=xlFormulas)
    If FoundCell Is Nothing Then
        MsgBox "Not Found"
    Else
        MsgBox FoundCell.Offset(0, 1)
    End If
End Sub

And, below code will get result "GGG"

1
2
3
4
5
6
7
8
9
Sub Button5a_Click()
    Dim FoundCell As Range
    Set FoundCell = Range("B44:B59").Find(What:="12/31/2015", LookIn:=xlValues)
    If FoundCell Is Nothing Then
        MsgBox "Not Found"
    Else
        MsgBox FoundCell.Offset(0, 1)
    End If
End Sub

Download File



No comments :

Post a Comment