can any one to resolve the problem with this vba code date row not found

Asif_80

New Member
Joined
Nov 17, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
can any one to resolve the problem with this vba code date row not found



VBA Code:
Private Sub CommandButton1_Click()

Dim R_Value As Range
Dim R_Found As Variant
Set R_Value = Sheets("Data").Rows.Find(CDate(Cmb1.Value), LookIn:=xlValues)
If Not R_Value Is Nothing Then
       R_Found = R_Value.Row
       R_Found.Select
Else
    MsgBox "No matching cell is found.", vbExclamation, "Row Number Not Found!"
    Exit Sub
End If

End Sub

Private Sub UserForm_Initialize()
 Cmb1.Value = Format((Cmb1.Value), "dd/mmm/yyyy")
End Sub
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I tried this code, and it worked fine. It selected the correct cell containing "01.01.2022".

VBA Code:
Private Sub CommandButton1_Click()

Dim R_Value As Range
Set R_Value = Sheets("Data").Rows.Find(CDate("01.01.2022"), LookIn:=xlValues)
If Not R_Value Is Nothing Then
    R_Value.Select
  Else
    MsgBox "No matching cell is found.", vbExclamation, "Row Number Not Found!"
End If

End Sub

What is Cmb1 in your Code? Must be a problem with your variable there.
 
Upvote 0
What is Cmb1 in your Code? Must be a problem with your variable there.

Try to change
VBA Code:
Cmb1.Value = Format((Cmb1.Value), "dd/mmm/yyyy")
to
VBA Code:
Cmb1.Text = Format((Cmb1.Value), "dd/mmm/yyyy")
 
Upvote 0
The cell you are searching for must contain a date and be formatted as date the same way as Cmb1 = "dd/mmm/yyyy".


VBA Code:
Private Sub CommandButton1_Click()

Dim R_Value As Range
Set R_Value = Sheets("Data").Rows.Find(CDate(Cmbl1.value), LookIn:=xlValues)
If Not R_Value Is Nothing Then
    R_Value.Select
  Else
    MsgBox "No matching cell is found.", vbExclamation, "Row Number Not Found!"
End If

End Sub

Private Sub UserForm_Initialize()
  Cmb1.Value = Format((Cmb1.Value), "dd/mmm/yyyy")
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top