Question : Insert Values

I need a way to insert values into a column
If ColumnA = "Top" then ColumnB = 1
If ColumnA= "Middle" then ColumnB = 2
If ColumnA = "Bottom" then ColunnB = 3

There are 1 heading rows and am using Excel 2007
and need to find the last row where ther is a value and stop

Thank you in advance

Answer : Insert Values

Use this code...

Saurabh...

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Sub insertvalues()
    Dim rng As Range, cell As Range

    Set rng = Range("A1:A" & Cells(Cells.Rows.Count, "a").End(xlUp).Row)

    For Each cell In rng
        If InStr(1, cell.Value, "Top", vbTextCompare) > 0 Then
            cell.Offset(0, 1).Value = 1
        ElseIf InStr(1, cell.Value, "Middle", vbTextCompare) > 0 Then
            cell.Offset(0, 1).Value = 2
        ElseIf InStr(1, cell.Value, "Bottom", vbTextCompare) > 0 Then
            cell.Offset(0, 1).Value = 3
        End If
    Next cell

End Sub
Random Solutions  
 
programming4us programming4us