userform question

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
I have a userform which allows user to selected a date formt he calendar. In my code I name the value selected myDate. I want to have a line of code at the begginning of my code that checks if myDate = a date already listed in column H on a sheet named "all dor's". if it does match then a msgbox appear saying "date already entered" and the code return to the opened userform.
 
it goes for about 3000 rows. and screen updating is off, but i was hoping to fix with a one line formula like vog was suggesting.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
any ideas why the part in red is not working to find a match in column H? if a match is found then it should show userform4, or basically return to the user form for my users to select another date:

Private Sub cmdOK_Click()
Application.ScreenUpdating = False
Dim Mylrow As Long, PLLrow As Long
Dim MyDate As Date, MyVsle As String
Dim R
Mylrow = Sheets("All DOR'S").Range("B18").End(xlDown).Row + 1
With UserForm4
MyDate = Calendar1.Value
End With
Sheets("all dor's").Activate
With ActiveSheet
If IsNumeric(Application.Match(MyDate, Range("H18:H" & Mylrow), 0)) Then
MsgBox "DOR of the date DATE has already been entered! Please select another date."
UserForm4.Show
else
End If
End With
Sheets("All DOR'S").Cells(Mylrow, 2).PasteSpecial xlValues
With UserForm4
MyDate = Calendar1.Value

For R = 0 To .lstbVessel.ListCount - 1
If .lstbVessel.Selected(R) = True Then ''get the vessle name
MyVsle = lstbVessel.List(R)
End If
Next
'''' now det the last row form the pasted values '''
PLLrow = Sheets("All DOR'S").Range("B65536").End(xlUp).Row
'''' fill column H for Date and Column I for Vessle '''
Sheets("All DOR'S").Range("H" & Mylrow & ":H" & PLLrow).Value = MyDate '' this is for the Date
Sheets("All DOR'S").Range("I" & Mylrow & ":I" & PLLrow).Value = MyVsle
End With
Unload UserForm4
MsgBox "DOR data added successfully!"
End Sub
 
Upvote 0
after numerous step thrus, this line is not appearently matching the values in my cells:

If IsNumeric(Application.Match(MyDate, ("H18:H" & Mylrow), 0)) = 1 Then


i have a matching date and everything but it is not finding it. ideas??
 
Upvote 0
Try this. Declare MyDate as a Date. Then

Code:
If IsNumeric(Application.Match(CDbl(MyDate), Range("H18:H30"), 0)) Then
 
Upvote 0
vog: how can i add in to also check for the variable named "MyVsle". it is not defined until later in the code? can you show me where I would need to move it up in the code?

Code:
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
Dim Mylrow As Long, PLLrow As Long
Dim MyDate As Date, MyVsle As String
Dim R
Mylrow = Sheets("All DOR'S").Range("B18").End(xlDown).Row + 1
With UserForm4
    MyDate = Calendar1.Value
    End With
        
    Sheets("all dor's").Activate
    With ActiveSheet
    If IsNumeric(Application.Match(CDbl(MyDate), Range("H18:H" & Mylrow), 0)) Then
    MsgBox "A DOR of the same date has already been entered! Please select another date."
    Exit Sub
    Else
    End If
    
    End With
Sheets("All DOR'S").Cells(Mylrow, 2).PasteSpecial xlValues
With UserForm4
    MyDate = Calendar1.Value
   
    For R = 0 To .lstbVessel.ListCount - 1
        If .lstbVessel.Selected(R) = True Then ''get the vessle name
            MyVsle = lstbVessel.List(R)
        End If
    Next
    '''' now det the last row form the pasted values '''
    PLLrow = Sheets("All DOR'S").Range("B65536").End(xlUp).Row
    '''' fill column H for Date and Column I for Vessle '''
    Sheets("All DOR'S").Range("H" & Mylrow & ":H" & PLLrow).Value = MyDate   '' this is for the Date
    Sheets("All DOR'S").Range("I" & Mylrow & ":I" & PLLrow).Value = MyVsle
End With
Unload UserForm4
MsgBox "DOR data added successfully!"
End Sub
 
Upvote 0
Try

Code:
    For R = 0 To .lstbVessel.ListCount - 1
        If .lstbVessel.Selected(R) = True Then ''get the vessle name
            MyVsle = lstbVessel.List(R)
        End If
    Next
    If IsNumeric(Application.Match(MyVsle, Range("I18:I" & Mylrow), 0)) Then
        MsgBox "Error message goes here."
        Exit Sub
    End If
 
Upvote 0
is that going to mean the same thing as:

If IsNumeric(Application.Match(CDbl(MyDate) & CDbl(MyVsle), Range("H18:H" & Mylrow), 0)) Then


i am wanting the code to check for both, and both must be true in order to show the msgbox, if both are not true then the code can paste as usual.
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

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