Loop through for condition and input in adjacent cell

B

bundyloco

I'm trying to write a macro that will loop through the cells in colum
to look for a certain string. If it is there, then print a string i
the adjacent cell in colum B. This will loop through until the end o
the range. Coumns A thru P have information in the cells. Here is m
code. I'm new to vb programming, so any information helps.

Dim a As String
Dim b As String
Dim cntr As Integer

ActiveSheet.Select 'Run on active sheet that is open

cntr = 1
'loop through cells to find product and input the corresonding rout
one cell to the right
Do
a = Cells(cntr, 1)
b = Cells(cntr, 7)
If a <> "" Or b <> "" Then 'Condition to stop at end o
range

If a = "Product A-1" Or "Greencreek B-0" Or "Greencreek B-0" O
"Blackford B-0" Then
ActiveCell.Offset(0, 1).Value = "123.abc"

ElseIf a = "Product B-1" Or "Calistoga A-3" Then
ActiveCell.Offset(0, 1).Value = "456.cde"

ElseIf a = "Product C-1" Then
ActiveCell.Offset(0, 1).Value = "789.fgh"

Else
cntr = cntr + 1
End If

Else
Exit Do
End If

Loop
End Su
 
B

Bob Phillips

This seems to be what you want

Dim a As String
Dim b As String
Dim cntr As Integer

'loop through cells to find product and input the corresonding route one
cell to the right
For cntr = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If a = "Product A-1" Or "Greencreek B-0" Or _
"Greencreek B-0" Or "Blackford B-0" Then
ActiveCell.Offset(0, 1).Value = "123.abc"
ElseIf a = "Product B-1" Or "Calistoga A-3" Then
ActiveCell.Offset(0, 1).Value = "456.cde"
ElseIf a = "Product C-1" Then
ActiveCell.Offset(0, 1).Value = "789.fgh"
Else
cntr = cntr + 1
End If
Next i
 

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

Top