IF , Then

S

Steve

Hello from Steved
In vba I would like to do the below please
In Column A:A
City to be 1-City
Roskill to be 2-Rosk
Papakura to be 3-Papa
Wiri to be 4-Wiri
Shore to be 5-Shore
Orewa to be 6-Orewa
Swanson to be 7-Swan
Panmure to be 8-Panm
Waiheke to be 9-Waih
An example would be City will Become 1-City
Thankyou,
 
P

pikus

For x = 1 To 9
Cells(x, 1).Value = x & "-" & Cells(x, 1).Value
Next x

Does that work for you? - Piku
 
B

Bob Phillips

In another column

=Row()&"-"&A1

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
S

Steved

Hello Pikus from Steved

Pikus please bare with me as I am a novice, thanks

Please if I type City anywhere in Column A:A
would the below vba return 1-City, if yes below is my
attempt

For City = 1
Cells(City, 1).Value = City & "1-City" & Cells(City,
1).Value
Next City

Thankyou.

-----Original Message-----
For x = 1 To 9
Cells(x, 1).Value = x & "-" & Cells(x, 1).Value
Next x

Does that work for you? - Pikus
 
P

pikus

I understand. Here is what the code I posted does if it is completel
unaltered. The line that says, “For x = 1 To 9” is used here to ru
through rows 1 – 9. It runs the code between that and “Next x” onc
for each row. The variable named “x” stands for the number of the ro
that is currently being worked with. It takes the information in th
first cell of the row, no matter what it says, and adds the number o
the row and a dash to the front of the value of the cell.
SO, if cell A1 says “city”, it gets changed to “1-city”
If it contains the word “airplane” it changes into “1-airplane”
Cell A2 goes from “candy” to “2-candy” and so on.

I was uncertain that I fully understood what you intended to accomplis
with this, so if this is not the affect you wanted, please let me know
Also, I want to stress that the code I posted should be use
unaltered. You should cut and paste it to wherever you want it an
change nothing. I would like to explain the code in a bit more detail
but I am on my way out the door. I'm sure someone else would be happ
to take care of that for you if you request it. - Piku
 

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