View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default If A1=H Then B1=1, Excel 2000 & 2003

Assume WH is in A1

in B1
=if(A1="H",1,if(A1="WH",2,if(A1="O",3,if(A1="B",4, if(A1="AN",5,"")))))

then drag fill down the column.

in code

Sub ABC()
Dim rng As Range
With Worksheets("Worksheet6")
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
rng.Offset(0, 1).Formula = "=if(A1=""H"",1,if(A1=""WH"",2" & _
",if(A1=""O"",3,if(A1=""B"",4,if(A1=""AN"",5,"""") ))))"
' Option to replace formulas with values:
rng.Offset(0, 1).Formula = rng.Offset(0, 1).Value
End Sub

--
Regards,
Tom Ogilvy



"jfcby" wrote in message
oups.com...
Hello,

On worksheet6 I have 500 rows of data. In columnA it has data like H,
WH, O, B, AN. In columnB I would to add 1, 2, 3, 4, 5. I want

What my worksheet looks like now ColumnB is blank:

ColumnA
WH
O
O
B
AN
H
H
H

The way I would for my sheet to look like:

ColumnA ColumnB
WH 2
O 3
O 3
B 4
AN 5
H 1
H 1
H 1

Thank you for your help in advance,
jfcby