Help with a Macro

I

Igneshwara reddy

Hi,

1) I have created a small macro where in it asks for my user ID when ever I
run this. I am not unable to run this macro.
2) If I am not giving the user ID in the prompt box then the macros should
end with the message as cancelled.
3) I need to set a format for the user id, it contains two alphabets and 6
numbers and I need to restrict to the format. For Ex: AA123456. I do not know
how to write the macros's for this format.

Kindly let me know how to do.

Range("C1").Select
ActiveCell.FormulaR1C1 = "Date"
Range("C2").Select = InputBox(Prompt:="Quickook")
If ID = True Then
Range("c3").Select
If ID = False Then
End
MsgBox "Cancelled"
End Sub

Regards,
Igneshwara reddy.
 
D

Dan R.

Try something like this:

Function pwdValid(pwd As Variant) As Boolean
pwdValid = True
If Not Len(pwd) = 8 Then
pwdValid = False
Exit Function
End If
For i = 1 To Len(pwd)
Select Case i
Case 1, 2
If Not UCase(Mid(pwd, i, 1)) Like "*[A-Z]*" Then
pwdValid = False
Exit Function
End If
Case Else
If Not Mid(pwd, i, 1) Like "*[0-9]*" Then
pwdValid = False
Exit Function
End If
End Select
Next i
End Function
 
H

Harald Staff

Another approach:

Sub test()
Dim ID As String
ID = InputBox("Who da man:")
MsgBox ID Like "[A-Z][A-Z]######"
End Sub

HTH. Best wishes Harald
 
I

Igneshwara reddy

Hi Harald,

This quite ok, but the results is displayed as False. Whatever the data I
enter it should be displayed in cell (C2) but that is not showing up now and
moreover the length of characters should be restricted to 8 if not the
function should exit without running the macro.

EX: the data will be as AA11111

Let me know if any other options available.

Regards,
Igneshwara reddy.

Harald Staff said:
Another approach:

Sub test()
Dim ID As String
ID = InputBox("Who da man:")
MsgBox ID Like "[A-Z][A-Z]######"
End Sub

HTH. Best wishes Harald

Igneshwara reddy said:
Hi,

1) I have created a small macro where in it asks for my user ID when ever
I
run this. I am not unable to run this macro.
2) If I am not giving the user ID in the prompt box then the macros should
end with the message as cancelled.
3) I need to set a format for the user id, it contains two alphabets and 6
numbers and I need to restrict to the format. For Ex: AA123456. I do not
know
how to write the macros's for this format.

Kindly let me know how to do.

Range("C1").Select
ActiveCell.FormulaR1C1 = "Date"
Range("C2").Select = InputBox(Prompt:="Quickook")
If ID = True Then
Range("c3").Select
If ID = False Then
End
MsgBox "Cancelled"
End Sub

Regards,
Igneshwara reddy.
 
H

Harald Staff

I was only trying to show how you can ensure that a string has two uppercase
letters followed six digits. AA11111 has five digits only, so it will return
false. Why do you want an invalid ID entry in a cell ?

There are multiple problems with the code you posted, I don't know what it
is supposed to do or where to start. But see if this gets you going:

Sub test()
Dim ID As String
ID = InputBox("Who da man:")
If ID = "" Then Exit Sub 'cancelled
If ID Like "[A-Z][A-Z]######" Then
Range("C2").Value = "Yo da man"
Range("D2").Value = "as accepted on " & now
Else
Range("C2").Value = "Denied"
Range("D2").value = "Formatting C:\ -please wait..."
Beep
End If
End Sub

Now test this using two uppercase letters and SIX digits ;-)

Best wishes Harald

Igneshwara reddy said:
Hi Harald,

This quite ok, but the results is displayed as False. Whatever the data I
enter it should be displayed in cell (C2) but that is not showing up now
and
moreover the length of characters should be restricted to 8 if not the
function should exit without running the macro.

EX: the data will be as AA11111

Let me know if any other options available.

Regards,
Igneshwara reddy.

Harald Staff said:
Another approach:

Sub test()
Dim ID As String
ID = InputBox("Who da man:")
MsgBox ID Like "[A-Z][A-Z]######"
End Sub

HTH. Best wishes Harald

Igneshwara reddy said:
Hi,

1) I have created a small macro where in it asks for my user ID when
ever
I
run this. I am not unable to run this macro.
2) If I am not giving the user ID in the prompt box then the macros
should
end with the message as cancelled.
3) I need to set a format for the user id, it contains two alphabets
and 6
numbers and I need to restrict to the format. For Ex: AA123456. I do
not
know
how to write the macros's for this format.

Kindly let me know how to do.

Range("C1").Select
ActiveCell.FormulaR1C1 = "Date"
Range("C2").Select = InputBox(Prompt:="Quickook")
If ID = True Then
Range("c3").Select
If ID = False Then
End
MsgBox "Cancelled"
End Sub

Regards,
Igneshwara reddy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top