Help w/ VBA code

  • Thread starter Thread starter J.B. Bobbitt
  • Start date Start date
J

J.B. Bobbitt

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
 
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
 

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

Back
Top