Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Loop Through Range

I am trying to loop through a range and if the first number in the
current cell in that range is between 1 and 8 I want to concationate
it with a value in another cell then past it in a cell 4 rows to the
left. Below is what I trying to get to work thank you in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False

Dim AcctRange As Range
Dim CellTest As Variant


Set AcctRange = Range("B5:B250")

For Each CellTest In AcctRange.Cells
If CellTest.Value(Left(CellTest.Value, 1) 3) And
CellTest.Value(Left(CellTest.Value, 1) < 8) Then
Set AcctRange.Offset(4, 0).Value = (Cells(1,
5).Value & CellTest.Value)
Else
Set AcctRange.Offset(, 4).Value = CellTest.Value

End If
Next

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Loop Through Range

I don't know why you would want this within a worksheet_change event.. If
you do want it to change with each entry in the range then it could be in
the event but written differently. Post back if this is your need.
Sub trythis()
dim c as range
For Each c In Range("b5:b250")
If Left(c, 1) 3 And Left(c, 1) < 8 Then
c.Offset(,-4) = Range("a5") & c
End If
Next c
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"newguy" wrote in message
...
I am trying to loop through a range and if the first number in the
current cell in that range is between 1 and 8 I want to concationate
it with a value in another cell then past it in a cell 4 rows to the
left. Below is what I trying to get to work thank you in advance.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False

Dim AcctRange As Range
Dim CellTest As Variant


Set AcctRange = Range("B5:B250")

For Each CellTest In AcctRange.Cells
If CellTest.Value(Left(CellTest.Value, 1) 3) And
CellTest.Value(Left(CellTest.Value, 1) < 8) Then
Set AcctRange.Offset(4, 0).Value = (Cells(1,
5).Value & CellTest.Value)
Else
Set AcctRange.Offset(, 4).Value = CellTest.Value

End If
Next

End Sub


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 through cells in a range and pick up corresponding cell values in another range [email protected] Excel Programming 9 October 19th 06 05:11 AM
How to use a Range in a Loop Glen Excel Programming 2 August 28th 06 02:51 AM
How to Loop Through This Range and... Faye[_2_] Excel Programming 3 May 3rd 06 03:29 PM
Add a Range to an existing Range in a loop? Mick Excel Programming 3 June 18th 05 06:12 AM
Loop through a range Fred[_21_] Excel Programming 6 October 22nd 04 10:45 PM


All times are GMT +1. The time now is 09:33 PM.

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"