Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Until non-incrementing cell condition met. GBExcel via OfficeKB.com Excel Worksheet Functions 3 November 4th 09 07:47 PM
Delete cell contents with input to adjacent cell Ashley Frank Excel Discussion (Misc queries) 1 October 5th 05 04:28 PM
loop non adjacent cells EWR Excel Programming 1 March 18th 05 05:05 PM
Loop to Next item in For Next on Condition [email protected] Excel Programming 2 September 1st 04 08:49 PM
two-condition loop Jamie Martin[_2_] Excel Programming 0 October 6th 03 11:47 PM


All times are GMT +1. The time now is 01:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"