ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA (https://www.excelbanter.com/excel-programming/299904-vba.html)

Steved[_3_]

VBA
 
Hello from Steved
Below runs if I push a macro assigned button.
Question using the below is it possible to type
City and when I use the enter key it will change it to
1-City.
Thankyou.

Sub test1()
Dim x As Long
For x = 1 To Range("a" & Rows.Count).End(xlUp).Row Step 1
Select Case Left(Cells(x, 1).Value, 4)
Case "City "
Cells(x, 1).Value = "1-City"
Case "Rosk"
Cells(x, 1).Value = "2-Rosk"
Case "Papa"
Cells(x, 1).Value = "3-Papa"
End Select
Next x
End Sub


Bob Phillips[_7_]

VBA
 
Steve,

Here is some worksheet event code


--
HTH

-------

Bob Phillips
"Steved" wrote in message
...
Hello from Steved
Below runs if I push a macro assigned button.
Question using the below is it possible to type
City and when I use the enter key it will change it to
1-City.
Thankyou.

Sub test1()
Dim x As Long
For x = 1 To Range("a" & Rows.Count).End(xlUp).Row Step 1
Select Case Left(Cells(x, 1).Value, 4)
Case "City "
Cells(x, 1).Value = "1-City"
Case "Rosk"
Cells(x, 1).Value = "2-Rosk"
Case "Papa"
Cells(x, 1).Value = "3-Papa"
End Select
Next x
End Sub




Bob Phillips[_7_]

VBA
 
Steve,

Here is some worksheet event code

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
With Target
Select Case LCase(Left(.Value, 4))
Case "city ": .Value = "1-City"
Case "rosk": .Value = "2-Rosk"
Case "papa": .Value = "3-Papa"
End Select
End With

ws_exit:
Application.EnableEvents = True
End Sub

To enter it, right-click the particular sheet tab, select View Code from the
menu, and then copy the code in.

--
HTH

-------

Bob Phillips
"Steved" wrote in message
...
Hello from Steved
Below runs if I push a macro assigned button.
Question using the below is it possible to type
City and when I use the enter key it will change it to
1-City.
Thankyou.

Sub test1()
Dim x As Long
For x = 1 To Range("a" & Rows.Count).End(xlUp).Row Step 1
Select Case Left(Cells(x, 1).Value, 4)
Case "City "
Cells(x, 1).Value = "1-City"
Case "Rosk"
Cells(x, 1).Value = "2-Rosk"
Case "Papa"
Cells(x, 1).Value = "3-Papa"
End Select
Next x
End Sub




Steved[_3_]

VBA
 
Helo Bob from Steved

Bob Thankyou very much

-----Original Message-----
Steve,

Here is some worksheet event code

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
With Target
Select Case LCase(Left(.Value, 4))
Case "city ": .Value = "1-City"
Case "rosk": .Value = "2-Rosk"
Case "papa": .Value = "3-Papa"
End Select
End With

ws_exit:
Application.EnableEvents = True
End Sub

To enter it, right-click the particular sheet tab, select

View Code from the
menu, and then copy the code in.

--
HTH

-------

Bob Phillips
"Steved" wrote in

message
...
Hello from Steved
Below runs if I push a macro assigned button.
Question using the below is it possible to type
City and when I use the enter key it will change it to
1-City.
Thankyou.

Sub test1()
Dim x As Long
For x = 1 To Range("a" & Rows.Count).End(xlUp).Row Step

1
Select Case Left(Cells(x, 1).Value, 4)
Case "City "
Cells(x, 1).Value = "1-City"
Case "Rosk"
Cells(x, 1).Value = "2-Rosk"
Case "Papa"
Cells(x, 1).Value = "3-Papa"
End Select
Next x
End Sub



.



All times are GMT +1. The time now is 03:23 AM.

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