Re: Help with a Macro



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" <Igneshwarareddy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:97275F65-797A-4549-AD9F-75003656BFDC@xxxxxxxxxxxxxxxx
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" wrote:

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" <Igneshwarareddy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:C43453F3-3D48-49C4-9DB3-539069D9823F@xxxxxxxxxxxxxxxx
> 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.



.