I have a command button where I input a well name in an input box. It returns the record in a msgbox. How do I get the date to display as a short date instead of a number.
This is the code I'm using:
Sub LOOKUP()
On Error GoTo MyErrorHandler:
Dim PRIMARY_WELLCOMP_SHORT_NAME As String
PRIMARY_WELLCOMP_SHORT_NAME = InputBox("Enter the Well Name :")
Det = "PRIMARY_WELLCOMP_SHORT_NAME : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 1, False)
Det = Det & vbNewLine & "WELL ANALYST : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 2, False)
Det = Det & vbNewLine & "OIL_RATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 3, False)
Det = Det & vbNewLine & "WATER_RATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 4, False)
Det = Det & vbNewLine & "GAS_RATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 5, False)
Det = Det & vbNewLine & "WELL_TEST_DATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 6, False)
Det = Det & vbNewLine & "TEST_FACILITY : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 7, False)
Det = Det & vbNewLine & "BATTERY_NAME : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 8, False)
MsgBox "Well Details : " & vbNewLine & Det
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
MsgBox "Well Not Listed in the table."
ElseIf Err.Number = 13 Then
MsgBox "You have entered an invalid value."
End If
End Sub
This is the message box that gets returned:
Thank you in advance!
Dan Rogotzke
This is the code I'm using:
Sub LOOKUP()
On Error GoTo MyErrorHandler:
Dim PRIMARY_WELLCOMP_SHORT_NAME As String
PRIMARY_WELLCOMP_SHORT_NAME = InputBox("Enter the Well Name :")
Det = "PRIMARY_WELLCOMP_SHORT_NAME : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 1, False)
Det = Det & vbNewLine & "WELL ANALYST : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 2, False)
Det = Det & vbNewLine & "OIL_RATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 3, False)
Det = Det & vbNewLine & "WATER_RATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 4, False)
Det = Det & vbNewLine & "GAS_RATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 5, False)
Det = Det & vbNewLine & "WELL_TEST_DATE : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 6, False)
Det = Det & vbNewLine & "TEST_FACILITY : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 7, False)
Det = Det & vbNewLine & "BATTERY_NAME : " & Application.WorksheetFunction.VLookup(PRIMARY_WELLCOMP_SHORT_NAME, Sheet1.Range("A2:H3219"), 8, False)
MsgBox "Well Details : " & vbNewLine & Det
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
MsgBox "Well Not Listed in the table."
ElseIf Err.Number = 13 Then
MsgBox "You have entered an invalid value."
End If
End Sub
This is the message box that gets returned:
Thank you in advance!
Dan Rogotzke