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.
 
vog, on the following code i am getting an invalid or unqualified refrence error on the line in red.

Code:
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
Dim Mylrow As Long, PLLrow As Long
Dim MyDate As Date, MyVsle As String
Dim mylrow2 As Long
Dim r
Sheets("Z").Activate
Sheets("Z").Range("A1").PasteSpecial Paste:=xlPasteValues
Sheets("all dor's").Activate
Sheets("all dor's").Unprotect Password:="techedit"
 
Mylrow = Sheets("All DOR'S").Range("B18").End(xlDown).Row + 1
Sheets("Z").UsedRange .Copy
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
   If IsNumeric(Application.Match(CDbl(MyDate), Range("H18:H" & Mylrow), 0)) And IsNumeric(Application.Match(MyVsle, Range("I18:I" & Mylrow), 0)) Then
    If Application.Match(CDbl(MyDate), Range("H18:H" & Mylrow), 0) = Application.Match(MyVsle, Range("I18:I" & Mylrow), 0) Then
        MsgBox "A DOR of the same date and vessel name has already been entered! Please select another date or a diffrent vessel."
        Exit Sub
    End If
End If
    Sheets("All DOR'S").Cells(Mylrow, 2).PasteSpecial xlValues
 
    '''' 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
Application.DisplayAlerts = False
Sheets("Z").UsedRange.ClearContents
Sheets("all dor's").Protect Password:="techedit"
Application.DisplayAlerts = True
MsgBox "DOR data added successfully!"
 
End Sub
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
the message says expected function or variable when a comma is used. I had mistyped in previous post.
 
Upvote 0
vog, am i right in understand this line of code:

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


it just says if the date matches anything in column H then true = if any vessel name matches in column I then true. so if true=true then...msgbox

thats not the same as verifying if the row each was matched on was the same row. that just makes sure both are matched before moving on. I am in need of a match being made on both plus having that match happen on the same row. to move on to msgbox.
 
Upvote 0
That does check if they are on the same row. Take a look at the MATCH function in Excel.
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,005
Members
449,279
Latest member
Faraz5023

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