Need help with giving one cell a value based upon another cells value

dan.norman

New Member
Joined
Apr 15, 2010
Messages
2
I need help with writing some sort of code that will look at everything I have in my "H" column and depending on what the cell contains, place a coresponding number into the next cell (column I). I am looking to do something sorta like this except to place the number in the entire column and not just I2.

Sub Test()
'
Set MyPage = Range("H2:H1200")
For Each Cell In Mypage

If Cell.Value = "YL/BL" Then
Range(I2).Value = 1
If Cell.Value = "YL/OR" Then
Range(I2).Value = 2
If Cell.Value = "YL/GR" Then
Range(I2).Value = 3
If Cell.Value = "YL/BR" Then
Range(I2).Value = 4
If Cell.Value = "YL/SL" Then
Range(I2).Value = 5
If Cell.Value = "YL/WH" Then
Range(I2).Value = 6
If Cell.Value = "YL/RD" Then
Range(I2).Value = 7
If Cell.Value = "YL/BK" Then
Range(I2).Value = 8
If Cell.Value = "YL/YL" Then
Range(I2).Value = 9
If Cell.Value = "YL/VI" Then
Range(I2).Value = 10
If Cell.Value = "YL/RS" Then
Range(I2).Value = 11
If Cell.Value = "YL/AQ" Then
Range(I2).Value = 12
If Cell.Value = "/0" Then
Range(I2).Value = 12
End If
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Give this a shot:

Code:
Public Sub DanNorman()
Dim rng     As Range, _
    Mypage  As Range
    
Set Mypage = Range("H2:H1200")
Application.ScreenUpdating = False
For Each rng In Mypage
    Select Case rng.Value
        Case "YL/BL"
            rng.Offset(0, 1).Value = 1
        Case "YL/OR"
            rng.Offset(0, 1).Value = 2
        Case "YL/GR"
            rng.Offset(0, 1).Value = 3
        Case "YL/BR"
            rng.Offset(0, 1).Value = 4
        Case "YL/SL"
            rng.Offset(0, 1).Value = 5
        Case "YL/WH"
            rng.Offset(0, 1).Value = 6
        Case "YL/RD"
            rng.Offset(0, 1).Value = 7
        Case "YL/BK"
            rng.Offset(0, 1).Value = 8
        Case "YL/YL"
            rng.Offset(0, 1).Value = 9
        Case "YL/VI"
            rng.Offset(0, 1).Value = 10
        Case "YL/RS"
            rng.Offset(0, 1).Value = 11
        Case "YL/AQ", "/0"
            rng.Offset(0, 1).Value = 12
        Case Else
    End Select
Next rng
Application.ScreenUpdating = True
End Sub
 
Upvote 0
try this

Code:
Sub Test2()
'
Set Mypage = Range("H2:H1200")
For Each Cell In Mypage
Select Case Cell
Case "YL/BL"
    Cell.Offset(, 1) = 1
Case Is = "YL/OR"
    Cell.Offset(, 1) = 2
Case Is = "YL/GR"
    Cell.Offset(, 1) = 3
Case Is = "YL/BR"
    Cell.Offset(, 1) = 4
Case Is = "YL/SL"
    Cell.Offset(, 1) = 5
Case Is = "YL/WH"
    Cell.Offset(, 1) = 6
Case Is = "YL/RD"
    Cell.Offset(, 1) = 7
Case Is = "YL/BK"
    Cell.Offset(, 1) = 8
Case Is = "YL/YL"
    Cell.Offset(, 1) = 9
Case Is = "YL/VI"
    Cell.Offset(, 1) = 10
Case Is = "YL/RS"
    Cell.Offset(, 1) = 11
Case Is = "YL/AQ"
    Cell.Offset(, 1) = 12
Case Is = "/0"
    Cell.Offset(, 1) = 12
End Select
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top