Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through for condition and input in adjacent cell
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 -- bundyloc ----------------------------------------------------------------------- bundyloco's Profile: http://www.excelforum.com/member.php...fo&userid=2338 View this thread: http://www.excelforum.com/showthread.php?threadid=38670 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop through for condition and input in adjacent cell
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 -- HTH Bob Phillips "bundyloco" wrote in message ... I'm trying to write a macro that will loop through the cells in colum A to look for a certain string. If it is there, then print a string in the adjacent cell in colum B. This will loop through until the end of the range. Coumns A thru P have information in the cells. Here is my 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 route one cell to the right Do a = Cells(cntr, 1) b = Cells(cntr, 7) If a < "" Or b < "" Then 'Condition to stop at end of range 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 Else Exit Do End If Loop End Sub -- bundyloco ------------------------------------------------------------------------ bundyloco's Profile: http://www.excelforum.com/member.php...o&userid=23386 View this thread: http://www.excelforum.com/showthread...hreadid=386705 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Loop Until non-incrementing cell condition met. | Excel Worksheet Functions | |||
Delete cell contents with input to adjacent cell | Excel Discussion (Misc queries) | |||
loop non adjacent cells | Excel Programming | |||
Loop to Next item in For Next on Condition | Excel Programming | |||
two-condition loop | Excel Programming |