PC Review


Reply
Thread Tools Rate Thread

Adding a counter to a variable name

 
 
Rich
Guest
Posts: n/a
 
      1st Aug 2008
I will be collecting values from multiple sheets.

How do I create a variable name with a counter attached to it, and how do I
declare that variable.

For example, I want variable names to be "DkType1", "DkType2", etc. I don't
know how many "DkType"s I will have.

Thanks!!!
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      1st Aug 2008
You probably want an array...

Sub stuff()
Dim DKType() As Variant
Dim lng As Long

ReDim DKType(lng)
DKType(lng) = Range("A1").Value
lng = lng + 1
ReDim Preserve DKType(lng)
DKType(lng) = Range("A2").Value
lng = lng + 1
ReDim Preserve DKType(lng)
DKType(lng) = Range("A3").Value

For lng = LBound(DKType) To UBound(DKType)
MsgBox DKType(lng)
Next lng

Range("C1:C3").Value = Application.Transpose(DKType) 'write the array
End Sub

--
HTH...

Jim Thomlinson


"Rich" wrote:

> I will be collecting values from multiple sheets.
>
> How do I create a variable name with a counter attached to it, and how do I
> declare that variable.
>
> For example, I want variable names to be "DkType1", "DkType2", etc. I don't
> know how many "DkType"s I will have.
>
> Thanks!!!

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counter variable and a multiplier LenS Microsoft Excel Misc 1 23rd Feb 2007 11:50 AM
Counter variable in For Loop almostmature@gmail.com Microsoft Excel Programming 3 8th Jun 2006 06:56 PM
Use XML to read/write a counter variable gce Microsoft ASP .NET 2 17th Mar 2005 05:51 PM
use counter variable when referencing control =?Utf-8?B?bWRpZGR5?= Microsoft VB .NET 1 12th Nov 2004 05:44 PM
variable counter/total Carole Microsoft Excel Programming 1 20th Oct 2003 07:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:37 AM.