Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Setting A variable name From Loop

Hello,
I am trying to set a few variables within a loop, The loop function is for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on how
to properly dimension this (these) variable(s) I would be greatly apreciative.

Thanks

Ironhydroxide
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Setting A variable name From Loop

Rusty,

Your code is such that I cannot tell what it is that you actually want to
do. Far better would be to describe (with words, and an example set of data)
what you want to do, and leave the coding to us.

HTH,
Bernie
MS Excel MVP


"ironhydroxide" wrote in message
...
Hello,
I am trying to set a few variables within a loop, The loop function is for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on
how
to properly dimension this (these) variable(s) I would be greatly
apreciative.

Thanks

Ironhydroxide


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Setting A variable name From Loop

Not to be rude, but if i left the coding to you then i would never learn how
to code it correctly.

Anyways, i have a list in a Previously selected sheet (still selected when
the code encounters the Do...Loop statement) I want to select the first
cell, save that to a variable called Zone1 (or ZoneOne, Whichever) and then
incriment to get one row down and compare this information with the
information already saved in the Zone1 (ZoneOne) Variable, If the
information is different, then i want the loop to declare a new variable
called Zone2 (Or ZoneTwo) and set it to the information in the cell, If it
is the same i want to incriment and move on, Continueing untill there is no
more information in the Cell (The list is continuous and is sorted
Alphabetically according to the column with the pertinent information)

The Variables I would like to create are almost indefinate (sp) as in, the
amount of needed variables is different every time this instance is run, But
i will never need over 100 variables.

In reply to the First reply,

The Loop would only run until the List has run out of information (or hits a
blank cell) then it would assign "" to the variable and satisfy the Loop
Until Variable is ""


I hope that this Explaination Helps

Ironhydroxide

"Bernie Deitrick" wrote:

Rusty,

Your code is such that I cannot tell what it is that you actually want to
do. Far better would be to describe (with words, and an example set of data)
what you want to do, and leave the coding to us.

HTH,
Bernie
MS Excel MVP


"ironhydroxide" wrote in message
...
Hello,
I am trying to set a few variables within a loop, The loop function is for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on
how
to properly dimension this (these) variable(s) I would be greatly
apreciative.

Thanks

Ironhydroxide



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Setting A variable name From Loop

Rusty,

Yes, if you left _all_ the coding to us, then you would never learn - but
you tried, and I will code my response in the way that you were approaching
the problem to show how to do it in that style. Note that the code that I
am showing you is NOT the best way to perform what you want to do - using
advanced filters to show unique values only is the best way - but I hope you
learn something. I have commented the code to help you understand. Also,
this is not bullet-proof code....

HTH,
Bernie
MS Excel MVP

Sub FindUniqueValues()

Dim myR As Range
Dim myVal() As Variant
Dim i As Integer
Dim j As Integer
Dim Msg As String

'Start with the array set to the value of the activecell
Set myR = ActiveCell
ReDim myVal(1 To 1)
myVal(1) = ActiveCell.Value
i = 1
While myR.Value < ""
'Check to see if the value has not been found (Match returns an
error)
'if it hasn't been found, expand the array and add the value
If IsError(Application.Match(myR.Value, myVal, False)) Then
'increment the counter
i = i + 1
'this expands the array without erasing the previous values
ReDim Preserve myVal(1 To i)
'add the value to the array
myVal(i) = myR.Value
End If
'go to the next cell down
Set myR = myR.Offset(1, 0)
Wend

'display the values that were found -
'this will show all the values in groups of up to 25,
'to show you how to access the values that were found

Msg = "I found " & UBound(myVal) & " unique values." & Chr(10) & _
"Here are 1 to " & _
Application.Min(UBound(myVal), 25) & ":" & Chr(10)
For i = LBound(myVal) To UBound(myVal)
Msg = Msg & Chr(10) & myVal(i)
If i Mod 25 = 0 Then
MsgBox Msg
Msg = "I found " & UBound(myVal) & _
" unique values." & Chr(10) & _
"Here are " & i + 1 & " to " & _
Application.Min(UBound(myVal), i + 25) & ":" & Chr(10)
End If
Next i
If UBound(myVal) Mod 25 < 0 Then MsgBox Msg


End Sub


"ironhydroxide" wrote in message
...
Not to be rude, but if i left the coding to you then i would never learn
how
to code it correctly.

Anyways, i have a list in a Previously selected sheet (still selected
when
the code encounters the Do...Loop statement) I want to select the first
cell, save that to a variable called Zone1 (or ZoneOne, Whichever) and
then
incriment to get one row down and compare this information with the
information already saved in the Zone1 (ZoneOne) Variable, If the
information is different, then i want the loop to declare a new variable
called Zone2 (Or ZoneTwo) and set it to the information in the cell, If
it
is the same i want to incriment and move on, Continueing untill there is
no
more information in the Cell (The list is continuous and is sorted
Alphabetically according to the column with the pertinent information)

The Variables I would like to create are almost indefinate (sp) as in,
the
amount of needed variables is different every time this instance is run,
But
i will never need over 100 variables.

In reply to the First reply,

The Loop would only run until the List has run out of information (or hits
a
blank cell) then it would assign "" to the variable and satisfy the Loop
Until Variable is ""


I hope that this Explaination Helps

Ironhydroxide

"Bernie Deitrick" wrote:

Rusty,

Your code is such that I cannot tell what it is that you actually want to
do. Far better would be to describe (with words, and an example set of
data)
what you want to do, and leave the coding to us.

HTH,
Bernie
MS Excel MVP


"ironhydroxide" wrote in
message
...
Hello,
I am trying to set a few variables within a loop, The loop function is
for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on
how
to properly dimension this (these) variable(s) I would be greatly
apreciative.

Thanks

Ironhydroxide




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Setting A variable name From Loop

With this is there then a way to select the second, (for that matter any of
the) Cell in the List? I know i am way out of my ball game here, I only
understand about 1/2 of the code that you posted (although it works how you
say it should)

"Bernie Deitrick" wrote:

Rusty,

Yes, if you left _all_ the coding to us, then you would never learn - but
you tried, and I will code my response in the way that you were approaching
the problem to show how to do it in that style. Note that the code that I
am showing you is NOT the best way to perform what you want to do - using
advanced filters to show unique values only is the best way - but I hope you
learn something. I have commented the code to help you understand. Also,
this is not bullet-proof code....

HTH,
Bernie
MS Excel MVP

Sub FindUniqueValues()

Dim myR As Range
Dim myVal() As Variant
Dim i As Integer
Dim j As Integer
Dim Msg As String

'Start with the array set to the value of the activecell
Set myR = ActiveCell
ReDim myVal(1 To 1)
myVal(1) = ActiveCell.Value
i = 1
While myR.Value < ""
'Check to see if the value has not been found (Match returns an
error)
'if it hasn't been found, expand the array and add the value
If IsError(Application.Match(myR.Value, myVal, False)) Then
'increment the counter
i = i + 1
'this expands the array without erasing the previous values
ReDim Preserve myVal(1 To i)
'add the value to the array
myVal(i) = myR.Value
End If
'go to the next cell down
Set myR = myR.Offset(1, 0)
Wend

'display the values that were found -
'this will show all the values in groups of up to 25,
'to show you how to access the values that were found

Msg = "I found " & UBound(myVal) & " unique values." & Chr(10) & _
"Here are 1 to " & _
Application.Min(UBound(myVal), 25) & ":" & Chr(10)
For i = LBound(myVal) To UBound(myVal)
Msg = Msg & Chr(10) & myVal(i)
If i Mod 25 = 0 Then
MsgBox Msg
Msg = "I found " & UBound(myVal) & _
" unique values." & Chr(10) & _
"Here are " & i + 1 & " to " & _
Application.Min(UBound(myVal), i + 25) & ":" & Chr(10)
End If
Next i
If UBound(myVal) Mod 25 < 0 Then MsgBox Msg


End Sub


"ironhydroxide" wrote in message
...
Not to be rude, but if i left the coding to you then i would never learn
how
to code it correctly.

Anyways, i have a list in a Previously selected sheet (still selected
when
the code encounters the Do...Loop statement) I want to select the first
cell, save that to a variable called Zone1 (or ZoneOne, Whichever) and
then
incriment to get one row down and compare this information with the
information already saved in the Zone1 (ZoneOne) Variable, If the
information is different, then i want the loop to declare a new variable
called Zone2 (Or ZoneTwo) and set it to the information in the cell, If
it
is the same i want to incriment and move on, Continueing untill there is
no
more information in the Cell (The list is continuous and is sorted
Alphabetically according to the column with the pertinent information)

The Variables I would like to create are almost indefinate (sp) as in,
the
amount of needed variables is different every time this instance is run,
But
i will never need over 100 variables.

In reply to the First reply,

The Loop would only run until the List has run out of information (or hits
a
blank cell) then it would assign "" to the variable and satisfy the Loop
Until Variable is ""


I hope that this Explaination Helps

Ironhydroxide

"Bernie Deitrick" wrote:

Rusty,

Your code is such that I cannot tell what it is that you actually want to
do. Far better would be to describe (with words, and an example set of
data)
what you want to do, and leave the coding to us.

HTH,
Bernie
MS Excel MVP


"ironhydroxide" wrote in
message
...
Hello,
I am trying to set a few variables within a loop, The loop function is
for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on
how
to properly dimension this (these) variable(s) I would be greatly
apreciative.

Thanks

Ironhydroxide






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Setting A variable name From Loop

The second value is

myVal(2)

To find the cell with the first of those values, use

myR.EntireColumn.Find(myVal(2)).Select

HTH,
Bernie
MS Excel MVP



"ironhydroxide" wrote in message
...
With this is there then a way to select the second, (for that matter any
of
the) Cell in the List? I know i am way out of my ball game here, I only
understand about 1/2 of the code that you posted (although it works how
you
say it should)

"Bernie Deitrick" wrote:

Rusty,

Yes, if you left _all_ the coding to us, then you would never learn - but
you tried, and I will code my response in the way that you were
approaching
the problem to show how to do it in that style. Note that the code that
I
am showing you is NOT the best way to perform what you want to do - using
advanced filters to show unique values only is the best way - but I hope
you
learn something. I have commented the code to help you understand. Also,
this is not bullet-proof code....

HTH,
Bernie
MS Excel MVP

Sub FindUniqueValues()

Dim myR As Range
Dim myVal() As Variant
Dim i As Integer
Dim j As Integer
Dim Msg As String

'Start with the array set to the value of the activecell
Set myR = ActiveCell
ReDim myVal(1 To 1)
myVal(1) = ActiveCell.Value
i = 1
While myR.Value < ""
'Check to see if the value has not been found (Match returns an
error)
'if it hasn't been found, expand the array and add the value
If IsError(Application.Match(myR.Value, myVal, False)) Then
'increment the counter
i = i + 1
'this expands the array without erasing the previous values
ReDim Preserve myVal(1 To i)
'add the value to the array
myVal(i) = myR.Value
End If
'go to the next cell down
Set myR = myR.Offset(1, 0)
Wend

'display the values that were found -
'this will show all the values in groups of up to 25,
'to show you how to access the values that were found

Msg = "I found " & UBound(myVal) & " unique values." & Chr(10) & _
"Here are 1 to " & _
Application.Min(UBound(myVal), 25) & ":" & Chr(10)
For i = LBound(myVal) To UBound(myVal)
Msg = Msg & Chr(10) & myVal(i)
If i Mod 25 = 0 Then
MsgBox Msg
Msg = "I found " & UBound(myVal) & _
" unique values." & Chr(10) & _
"Here are " & i + 1 & " to " & _
Application.Min(UBound(myVal), i + 25) & ":" & Chr(10)
End If
Next i
If UBound(myVal) Mod 25 < 0 Then MsgBox Msg


End Sub


"ironhydroxide" wrote in
message
...
Not to be rude, but if i left the coding to you then i would never
learn
how
to code it correctly.

Anyways, i have a list in a Previously selected sheet (still selected
when
the code encounters the Do...Loop statement) I want to select the
first
cell, save that to a variable called Zone1 (or ZoneOne, Whichever) and
then
incriment to get one row down and compare this information with the
information already saved in the Zone1 (ZoneOne) Variable, If the
information is different, then i want the loop to declare a new
variable
called Zone2 (Or ZoneTwo) and set it to the information in the cell,
If
it
is the same i want to incriment and move on, Continueing untill there
is
no
more information in the Cell (The list is continuous and is sorted
Alphabetically according to the column with the pertinent information)

The Variables I would like to create are almost indefinate (sp) as in,
the
amount of needed variables is different every time this instance is
run,
But
i will never need over 100 variables.

In reply to the First reply,

The Loop would only run until the List has run out of information (or
hits
a
blank cell) then it would assign "" to the variable and satisfy the
Loop
Until Variable is ""


I hope that this Explaination Helps

Ironhydroxide

"Bernie Deitrick" wrote:

Rusty,

Your code is such that I cannot tell what it is that you actually want
to
do. Far better would be to describe (with words, and an example set of
data)
what you want to do, and leave the coding to us.

HTH,
Bernie
MS Excel MVP


"ironhydroxide" wrote in
message
...
Hello,
I am trying to set a few variables within a loop, The loop function
is
for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable)
Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me
on
how
to properly dimension this (these) variable(s) I would be greatly
apreciative.

Thanks

Ironhydroxide





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Setting A variable name From Loop

I have read up a bit, and apparently what i am looking for is to delcare a
variable that takes its name from a string. like "String1" then taking that
string and making a variable from it... String1=.....

I think this is called a Dynamic Variable

"ironhydroxide" wrote:

Not to be rude, but if i left the coding to you then i would never learn how
to code it correctly.

Anyways, i have a list in a Previously selected sheet (still selected when
the code encounters the Do...Loop statement) I want to select the first
cell, save that to a variable called Zone1 (or ZoneOne, Whichever) and then
incriment to get one row down and compare this information with the
information already saved in the Zone1 (ZoneOne) Variable, If the
information is different, then i want the loop to declare a new variable
called Zone2 (Or ZoneTwo) and set it to the information in the cell, If it
is the same i want to incriment and move on, Continueing untill there is no
more information in the Cell (The list is continuous and is sorted
Alphabetically according to the column with the pertinent information)

The Variables I would like to create are almost indefinate (sp) as in, the
amount of needed variables is different every time this instance is run, But
i will never need over 100 variables.

In reply to the First reply,

The Loop would only run until the List has run out of information (or hits a
blank cell) then it would assign "" to the variable and satisfy the Loop
Until Variable is ""


I hope that this Explaination Helps

Ironhydroxide

"Bernie Deitrick" wrote:

Rusty,

Your code is such that I cannot tell what it is that you actually want to
do. Far better would be to describe (with words, and an example set of data)
what you want to do, and leave the coding to us.

HTH,
Bernie
MS Excel MVP


"ironhydroxide" wrote in message
...
Hello,
I am trying to set a few variables within a loop, The loop function is for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on
how
to properly dimension this (these) variable(s) I would be greatly
apreciative.

Thanks

Ironhydroxide



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Setting A variable name From Loop


Your problem is your loop may never end and it will loop forever. Zone and
Zone number only change when the IF condition is true. If you don't get into
the IF statement you end up in an endless loop. I can't tell wha you are
trying to do with this code so I can't recommend a solution.
"ironhydroxide" wrote:

Hello,
I am trying to set a few variables within a loop, The loop function is for
the variables specifically.

I would like something to this effect

------------------------------------------------------------------------------------------------
ZoneNumber = 1
ZoneFromRow = 2
"Zone"& ZoneNumber = Cells(ZoneFromRow, 4)
Do
ZoneFromRow = ZoneFromRow + 1
If Cells(ZoneFromRow, 4) < "Zone" & ZoneNumber(variable) Then
ZoneNumber = ZoneNumber + 1
"Zone"& ZoneNumber=Cells(ZoneFromRow, 4)
End If
Loop Until "Zone" & ZoneNumber = ""
------------------------------------------------------------------------------------------------

Apparently i am doing this wrong. If someone could please inform me on how
to properly dimension this (these) variable(s) I would be greatly apreciative.

Thanks

Ironhydroxide

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
Setting Multiple Variables with a loop jlclyde Excel Discussion (Misc queries) 6 November 11th 09 09:40 PM
For Each ... Next loop - need to reference the loop variable [email protected] Excel Programming 4 July 13th 06 06:12 PM
Setting a range within a loop variable for copy/paste Craig[_24_] Excel Programming 3 December 21st 05 04:05 PM
TextToColumns delimiter setting ignored w/in VB loop Amy[_8_] Excel Programming 0 February 15th 05 07:15 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM


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