Looping to create Variable Names?

  • Thread starter Thread starter Jill E
  • Start date Start date
J

Jill E

Hi,

I have a whole wack of variables to name and populate and I thought it would
be appropriate to use a loop to do so. Unfortunately I'm having problems
getting it to work.

Specifically I am trying to create several variables called "VTitleBold"
with a number assigned to it which indicates the column, ie TitleBold1,
TitleBold2, TitleBold3.

So I did a count of the number of columns in question (counter) and then:

For NumberOfColumns = 1 To counter
TitleBold = "vcTitleBold" & NumberOfColumns
vcTitleBold = ActiveCell.Font.Bold
....
Next NumberOfColumns

The second line did what I wanted but was instantly replaced by the next
line.

Please help!

Thanks,

Jill E
 
Hi,

I have a whole wack of variables to name and populate and I thought it would
be appropriate to use a loop to do so. Unfortunately I'm having problems
getting it to work.

Specifically I am trying to create several variables called "VTitleBold"
with a number assigned to it which indicates the column, ie TitleBold1,
TitleBold2, TitleBold3.

So I did a count of the number of columns in question (counter) and then:

For NumberOfColumns = 1 To counter
TitleBold = "vcTitleBold" & NumberOfColumns
vcTitleBold = ActiveCell.Font.Bold
...
Next NumberOfColumns

The second line did what I wanted but was instantly replaced by the next
line.

Make it an array:
Dim VTitleBold(1 to counter) as String
For n = 1 To counter
VTitleBold(n) = ActiveCell.Font.Bold
[...]
Next
(Might have to change Dim -> ReDim.)
 
Thankyou! It worked!

Jill E

Auric__ said:
Hi,

I have a whole wack of variables to name and populate and I thought it would
be appropriate to use a loop to do so. Unfortunately I'm having problems
getting it to work.

Specifically I am trying to create several variables called "VTitleBold"
with a number assigned to it which indicates the column, ie TitleBold1,
TitleBold2, TitleBold3.

So I did a count of the number of columns in question (counter) and then:

For NumberOfColumns = 1 To counter
TitleBold = "vcTitleBold" & NumberOfColumns
vcTitleBold = ActiveCell.Font.Bold
...
Next NumberOfColumns

The second line did what I wanted but was instantly replaced by the next
line.

Make it an array:
Dim VTitleBold(1 to counter) as String
For n = 1 To counter
VTitleBold(n) = ActiveCell.Font.Bold
[...]
Next
(Might have to change Dim -> ReDim.)
 
Make it an array:
Dim VTitleBold(1 to counter) as String
For n = 1 To counter
VTitleBold(n) = ActiveCell.Font.Bold
[...]
Next
(Might have to change Dim -> ReDim.)

Correction: if VTitleBold just holds ActiveCell.Font.Bold (a boolean
value) then dim it as boolean, not string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top