Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Sequential looping

Group,

I am stuck on a problem in looping. Im trying to make it
so that I do not have to write 5 procedures for the 5
different Variables. But im getting an error with my
integer changing and the macro recognizing it as a
variable.

Thanks in advance


Fish

'''''Code

Dim x as integer
Dim Med1 As String, Med2 As String, Med3 As String, Med4
As String, Med5 As String


Med2 = "Advil"
Med3 = "Aleve"
Med4 = "Aspirin"
Med5 = "NyQuil"
Med6 = "Day Quil"

x = 1

Do
Med = Med1 + x
ActiveCell.Offset(0, -1).Value = Med
ActiveCell.Offset(1, 0).Select
x = x + 1
Loop Until ActiveCell.Offset(-1, -1).Value = Med6

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Sequential looping

Hi
use an array. something like
Dim amed(0 to 5)

and loop through this array

"FISH" wrote:

Group,

I am stuck on a problem in looping. Im trying to make it
so that I do not have to write 5 procedures for the 5
different Variables. But im getting an error with my
integer changing and the macro recognizing it as a
variable.

Thanks in advance


Fish

'''''Code

Dim x as integer
Dim Med1 As String, Med2 As String, Med3 As String, Med4
As String, Med5 As String


Med2 = "Advil"
Med3 = "Aleve"
Med4 = "Aspirin"
Med5 = "NyQuil"
Med6 = "Day Quil"

x = 1

Do
Med = Med1 + x
ActiveCell.Offset(0, -1).Value = Med
ActiveCell.Offset(1, 0).Select
x = x + 1
Loop Until ActiveCell.Offset(-1, -1).Value = Med6


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Sequential looping

You cannot construct a variable name so, like Frank said, try an array. For
example:

Sub a()
Dim Counter As Integer
Dim MyArray As Variant
MyArray = Array("a", "b", "c", "d", "e")
For Counter = 0 To UBound(MyArray)
ActiveCell.Offset(Counter).Value = MyArray(Counter)
Next
End Sub

--
Jim Rech
Excel MVP
"FISH" wrote in message
...
| Group,
|
| I am stuck on a problem in looping. Im trying to make it
| so that I do not have to write 5 procedures for the 5
| different Variables. But im getting an error with my
| integer changing and the macro recognizing it as a
| variable.
|
| Thanks in advance
|
|
| Fish
|
| '''''Code
|
| Dim x as integer
| Dim Med1 As String, Med2 As String, Med3 As String, Med4
| As String, Med5 As String
|
|
| Med2 = "Advil"
| Med3 = "Aleve"
| Med4 = "Aspirin"
| Med5 = "NyQuil"
| Med6 = "Day Quil"
|
| x = 1
|
| Do
| Med = Med1 + x
| ActiveCell.Offset(0, -1).Value = Med
| ActiveCell.Offset(1, 0).Select
| x = x + 1
| Loop Until ActiveCell.Offset(-1, -1).Value = Med6
|


  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Sequential looping

Two things off the top of my head (and it doesn't often go much deeper):
1) Your Dims are Med1 through Med5, but your assigns are Med2 through Med6.
2) I don't think you can add the integer "x" to the last character of the
string name "Med#" to increment to the next string.

You would probably be better off using Select Case.

Ed

"FISH" wrote in message
...
Group,

I am stuck on a problem in looping. Im trying to make it
so that I do not have to write 5 procedures for the 5
different Variables. But im getting an error with my
integer changing and the macro recognizing it as a
variable.

Thanks in advance


Fish

'''''Code

Dim x as integer
Dim Med1 As String, Med2 As String, Med3 As String, Med4
As String, Med5 As String


Med2 = "Advil"
Med3 = "Aleve"
Med4 = "Aspirin"
Med5 = "NyQuil"
Med6 = "Day Quil"

x = 1

Do
Med = Med1 + x
ActiveCell.Offset(0, -1).Value = Med
ActiveCell.Offset(1, 0).Select
x = x + 1
Loop Until ActiveCell.Offset(-1, -1).Value = Med6



  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Sequential looping


Thanks a bunch Frank



-----Original Message-----
Hi
use an array. something like
Dim amed(0 to 5)

and loop through this array

"FISH" wrote:

Group,

I am stuck on a problem in looping. Im trying to make

it
so that I do not have to write 5 procedures for the 5
different Variables. But im getting an error with my
integer changing and the macro recognizing it as a
variable.

Thanks in advance


Fish

'''''Code

Dim x as integer
Dim Med1 As String, Med2 As String, Med3 As String,

Med4
As String, Med5 As String


Med2 = "Advil"
Med3 = "Aleve"
Med4 = "Aspirin"
Med5 = "NyQuil"
Med6 = "Day Quil"

x = 1

Do
Med = Med1 + x
ActiveCell.Offset(0, -1).Value = Med
ActiveCell.Offset(1, 0).Select
x = x + 1
Loop Until ActiveCell.Offset(-1, -1).Value = Med6


.

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
Sequential Numbers abcdexcel Excel Discussion (Misc queries) 3 January 18th 06 11:06 AM
sequential numbers Harley Excel Worksheet Functions 1 January 12th 06 09:57 PM
sequential numbers AndrewRichardWood Excel Discussion (Misc queries) 2 July 20th 05 05:00 PM
Non-sequential VLOOKUP function -OR- sequential sort of web query Eric S Excel Worksheet Functions 1 February 28th 05 07:50 PM
Sequential names on Sequential pages Salt4 Excel Worksheet Functions 2 November 12th 04 04:24 PM


All times are GMT +1. The time now is 10:05 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"