Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Looping and String Variable


I use this code to find a match of Val1 in a row of cells, though also have
Val2, 3 ,4 etc also

For j = StrtCol To EndCol
If ActiveCell = Val1 Then
Call Get_Data
Else
ActiveCell.Offset(0, 1).Select
End j

I turned the val variable into a String called Val() though not sure how the
syntax works to look for e.g. Val(1 to 5) in the row of the cells and return
data below it.
The Val is text.

For Each i In Val(i)?

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Looping and String Variable

There are many ways to do what I think you want so here's one that should
get you started. A couple things about your code though. First, Val is a
built-in VB function so you shouldn't use it for a variable's name. Second,
moving the active cell via code is slow and unnecessary.

Sub demo()
Dim ValArray(1 To 5) As String
Dim Cell As Range, MatchIdx As Variant
ValArray(1) = "a"
ValArray(2) = "b"
ValArray(3) = "c"
ValArray(4) = "d"
ValArray(5) = "e"
For Each Cell In Range("A1:E1")
MatchIdx = Application.Match(Cell.Value, ValArray, False)
If Not IsError(MatchIdx) Then
MsgBox Cell.Offset(1).Value
End If
Next
End Sub


--
Jim Rech
Excel MVP
"Mourinho" wrote in message
...
|
| I use this code to find a match of Val1 in a row of cells, though also
have
| Val2, 3 ,4 etc also
|
| For j = StrtCol To EndCol
| If ActiveCell = Val1 Then
| Call Get_Data
| Else
| ActiveCell.Offset(0, 1).Select
| End j
|
| I turned the val variable into a String called Val() though not sure how
the
| syntax works to look for e.g. Val(1 to 5) in the row of the cells and
return
| data below it.
| The Val is text.
|
| For Each i In Val(i)?
|
| Thanks
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Looping and String Variable

Thanks Jim,

I'm new to this, so new methods are gold dust to me...

I also have to continue the same search in a new Row further down the sheet,
so I would want to include that: For Each row (every x rows), For Each Cell
in Range, For Each Variable (ValArray1,2etc), match and return value below.

Cheers

"Jim Rech" wrote:

There are many ways to do what I think you want so here's one that should
get you started. A couple things about your code though. First, Val is a
built-in VB function so you shouldn't use it for a variable's name. Second,
moving the active cell via code is slow and unnecessary.

Sub demo()
Dim ValArray(1 To 5) As String
Dim Cell As Range, MatchIdx As Variant
ValArray(1) = "a"
ValArray(2) = "b"
ValArray(3) = "c"
ValArray(4) = "d"
ValArray(5) = "e"
For Each Cell In Range("A1:E1")
MatchIdx = Application.Match(Cell.Value, ValArray, False)
If Not IsError(MatchIdx) Then
MsgBox Cell.Offset(1).Value
End If
Next
End Sub


--
Jim Rech
Excel MVP
"Mourinho" wrote in message
...
|
| I use this code to find a match of Val1 in a row of cells, though also
have
| Val2, 3 ,4 etc also
|
| For j = StrtCol To EndCol
| If ActiveCell = Val1 Then
| Call Get_Data
| Else
| ActiveCell.Offset(0, 1).Select
| End j
|
| I turned the val variable into a String called Val() though not sure how
the
| syntax works to look for e.g. Val(1 to 5) in the row of the cells and
return
| data below it.
| The Val is text.
|
| For Each i In Val(i)?
|
| Thanks
|
|



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping and String Variable

For j = StrtCol To EndCol
for k = 1 to 5
If ActiveCell = Val(k) Then
Call Get_Data
End if
Next k
ActiveCell.Offset(0, 1).Select
Next j

--
Regards,
Tom Ogilvy

"Mourinho" wrote in message
...

I use this code to find a match of Val1 in a row of cells, though also

have
Val2, 3 ,4 etc also

For j = StrtCol To EndCol
If ActiveCell = Val1 Then
Call Get_Data
Else
ActiveCell.Offset(0, 1).Select
End j

I turned the val variable into a String called Val() though not sure how

the
syntax works to look for e.g. Val(1 to 5) in the row of the cells and

return
data below it.
The Val is text.

For Each i In Val(i)?

Thanks




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Looping and String Variable

Well, at the risk of making this inscrutable<g, this example assumes you
want to operate on row 1 and every tenth row after that (11, 21, 31, etc,)
to row 101:

Sub demo2()
Dim ValArray(1 To 5) As String
Dim Cell As Range, MatchIdx As Variant
Dim RowOffset As Integer
ValArray(1) = "a": ValArray(2) = "b"
ValArray(3) = "c": ValArray(4) = "d"
ValArray(5) = "e"
For RowOffset = 0 To 90 Step 10
For Each Cell In Range("A1:E1").Offset(RowOffset)
MatchIdx = Application.Match(Cell.Value, ValArray, False)
If Not IsError(MatchIdx) Then
MsgBox Cell.Offset(1).Value
End If
Next
Next
End Sub


--
Jim Rech
Excel MVP
"Mourinho" wrote in message
...
| Thanks Jim,
|
| I'm new to this, so new methods are gold dust to me...
|
| I also have to continue the same search in a new Row further down the
sheet,
| so I would want to include that: For Each row (every x rows), For Each
Cell
| in Range, For Each Variable (ValArray1,2etc), match and return value
below.
|
| Cheers
|
| "Jim Rech" wrote:
|
| There are many ways to do what I think you want so here's one that
should
| get you started. A couple things about your code though. First, Val is
a
| built-in VB function so you shouldn't use it for a variable's name.
Second,
| moving the active cell via code is slow and unnecessary.
|
| Sub demo()
| Dim ValArray(1 To 5) As String
| Dim Cell As Range, MatchIdx As Variant
| ValArray(1) = "a"
| ValArray(2) = "b"
| ValArray(3) = "c"
| ValArray(4) = "d"
| ValArray(5) = "e"
| For Each Cell In Range("A1:E1")
| MatchIdx = Application.Match(Cell.Value, ValArray, False)
| If Not IsError(MatchIdx) Then
| MsgBox Cell.Offset(1).Value
| End If
| Next
| End Sub
|
|
| --
| Jim Rech
| Excel MVP
| "Mourinho" wrote in message
| ...
| |
| | I use this code to find a match of Val1 in a row of cells, though also
| have
| | Val2, 3 ,4 etc also
| |
| | For j = StrtCol To EndCol
| | If ActiveCell = Val1 Then
| | Call Get_Data
| | Else
| | ActiveCell.Offset(0, 1).Select
| | End j
| |
| | I turned the val variable into a String called Val() though not sure
how
| the
| | syntax works to look for e.g. Val(1 to 5) in the row of the cells and
| return
| | data below it.
| | The Val is text.
| |
| | For Each i In Val(i)?
| |
| | Thanks
| |
| |
|
|
|


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
Looping to create Variable Names? Jill E Excel Programming 3 August 10th 04 12:17 AM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
How do I convert an integer variable to a string variable? dumbass Excel Programming 2 May 21st 04 07:34 PM
building a text string while looping though a worksheet Phillips Excel Programming 4 December 10th 03 08:31 AM
Increment a variable while looping ibeetb Excel Programming 2 September 25th 03 07:15 PM


All times are GMT +1. The time now is 10:20 PM.

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

About Us

"It's about Microsoft Excel"