ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help w/ VBA code (https://www.excelbanter.com/excel-programming/321939-help-w-vba-code.html)

J.B. Bobbitt

Help w/ VBA code
 
Hi;

I'm new to VBA and need to get A LOT done quickly. I need help with some
simple code for the following:

I have a sheet with a column (~1500 rows) in which each cell contians a
numeric value. I want to create a new column in which cell contains a text
string based on the numeric value in the first column; i.e.:

If A1 < 0, then B1="string1"
If A1 =0, then B1="string2"

and so on for all cells in column.

Any help, suggestions?

Thanks in advance,
-jbb



JulieD

Help w/ VBA code
 
Hi

personally i wouldn't worry about using VBA for this - i would type an IF
formula
=IF(A1<0,"string1","string2")
in cell B1 and then double click the autofill handle (bottom right hand
corner of the cell) - then i would select column B and copy - edit / paste
special values

however, if you do want code

Sub addstrings()
For Each c In Range("A1:A1500") 'set range to suit
If c.Value < 0 Then
c.Offset(0, 1).Value = "string1"
Else
c.Offset(0, 1).Value = "string2"
End If
Next
End Sub

--- note, this code assumes that column B is blank and can be used for entry
of the strings. It also assumes that each cell in column A has a number
either less than zero, zero or greater than zero.

Hope this helps
Cheers
JulieD


"J.B. Bobbitt" wrote in message
k.net...
Hi;

I'm new to VBA and need to get A LOT done quickly. I need help with some
simple code for the following:

I have a sheet with a column (~1500 rows) in which each cell contians a
numeric value. I want to create a new column in which cell contains a
text string based on the numeric value in the first column; i.e.:

If A1 < 0, then B1="string1"
If A1 =0, then B1="string2"

and so on for all cells in column.

Any help, suggestions?

Thanks in advance,
-jbb




J.B. Bobbitt

Help w/ VBA code
 
Thanks and a hat tip, Julie. I'm off and running.

-jbb

"JulieD" wrote in message
...
Hi

personally i wouldn't worry about using VBA for this - i would type an IF
formula
=IF(A1<0,"string1","string2")
in cell B1 and then double click the autofill handle (bottom right hand
corner of the cell) - then i would select column B and copy - edit / paste
special values

however, if you do want code

Sub addstrings()
For Each c In Range("A1:A1500") 'set range to suit
If c.Value < 0 Then
c.Offset(0, 1).Value = "string1"
Else
c.Offset(0, 1).Value = "string2"
End If
Next
End Sub

--- note, this code assumes that column B is blank and can be used for
entry of the strings. It also assumes that each cell in column A has a
number either less than zero, zero or greater than zero.

Hope this helps
Cheers
JulieD


"J.B. Bobbitt" wrote in message
k.net...
Hi;

I'm new to VBA and need to get A LOT done quickly. I need help with some
simple code for the following:

I have a sheet with a column (~1500 rows) in which each cell contians a
numeric value. I want to create a new column in which cell contains a
text string based on the numeric value in the first column; i.e.:

If A1 < 0, then B1="string1"
If A1 =0, then B1="string2"

and so on for all cells in column.

Any help, suggestions?

Thanks in advance,
-jbb






JulieD

Help w/ VBA code
 
you're welcome ... do come back if you get stuck again.

"J.B. Bobbitt" wrote in message
nk.net...
Thanks and a hat tip, Julie. I'm off and running.

-jbb

"JulieD" wrote in message
...
Hi

personally i wouldn't worry about using VBA for this - i would type an IF
formula
=IF(A1<0,"string1","string2")
in cell B1 and then double click the autofill handle (bottom right hand
corner of the cell) - then i would select column B and copy - edit /
paste special values

however, if you do want code

Sub addstrings()
For Each c In Range("A1:A1500") 'set range to suit
If c.Value < 0 Then
c.Offset(0, 1).Value = "string1"
Else
c.Offset(0, 1).Value = "string2"
End If
Next
End Sub

--- note, this code assumes that column B is blank and can be used for
entry of the strings. It also assumes that each cell in column A has a
number either less than zero, zero or greater than zero.

Hope this helps
Cheers
JulieD


"J.B. Bobbitt" wrote in message
k.net...
Hi;

I'm new to VBA and need to get A LOT done quickly. I need help with
some simple code for the following:

I have a sheet with a column (~1500 rows) in which each cell contians a
numeric value. I want to create a new column in which cell contains a
text string based on the numeric value in the first column; i.e.:

If A1 < 0, then B1="string1"
If A1 =0, then B1="string2"

and so on for all cells in column.

Any help, suggestions?

Thanks in advance,
-jbb








J.B. Bobbitt

Help w/ VBA code
 
Oh, I will............. (and have).

-jbb


"JulieD" wrote in message
...
you're welcome ... do come back if you get stuck again.

"J.B. Bobbitt" wrote in message
nk.net...
Thanks and a hat tip, Julie. I'm off and running.

-jbb

"JulieD" wrote in message
...
Hi

personally i wouldn't worry about using VBA for this - i would type an
IF formula
=IF(A1<0,"string1","string2")
in cell B1 and then double click the autofill handle (bottom right hand
corner of the cell) - then i would select column B and copy - edit /
paste special values

however, if you do want code

Sub addstrings()
For Each c In Range("A1:A1500") 'set range to suit
If c.Value < 0 Then
c.Offset(0, 1).Value = "string1"
Else
c.Offset(0, 1).Value = "string2"
End If
Next
End Sub

--- note, this code assumes that column B is blank and can be used for
entry of the strings. It also assumes that each cell in column A has a
number either less than zero, zero or greater than zero.

Hope this helps
Cheers
JulieD


"J.B. Bobbitt" wrote in message
k.net...
Hi;

I'm new to VBA and need to get A LOT done quickly. I need help with
some simple code for the following:

I have a sheet with a column (~1500 rows) in which each cell contians a
numeric value. I want to create a new column in which cell contains a
text string based on the numeric value in the first column; i.e.:

If A1 < 0, then B1="string1"
If A1 =0, then B1="string2"

and so on for all cells in column.

Any help, suggestions?

Thanks in advance,
-jbb











All times are GMT +1. The time now is 05:47 PM.

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