ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with a Macro (https://www.excelbanter.com/excel-programming/412652-help-macro.html)

Igneshwara reddy[_2_]

Help with a Macro
 
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.

Dan R.

Help with a Macro
 
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

--
Dan


On Jun 16, 9:33*am, Igneshwara reddy
wrote:
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.


Harald Staff[_2_]

Help with a Macro
 
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" wrote in
message ...
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.



Igneshwara reddy[_2_]

Help with a Macro
 
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" wrote in
message ...
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.




Harald Staff[_2_]

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" wrote in
message ...
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" wrote in
message ...
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.






All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com