is there a way to turn this into a variable statement?

m_in_spain

Board Regular
Joined
Sep 28, 2018
Messages
72
Office Version
  1. 365
Platform
  1. Windows
Hi, I have the following simple line of code:

VBA Code:
Ch4Actual.ingredients4.Visible = True

Ingredients4 is a listview, I have a variable, Dim k as Integer.,Ch4Actual is the UserForm
My question: Is it possible to replace the number 4 in my code with k so i can easily change a whole page of code which uses this line many times?

i have tried things like:
("Ch & k & Actual.ingredients & k").Visible = True
but no luck!
Many thanks for any advice or help
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
well, here you go

VBA Code:
k = 4
Controls("ingredients" & k).Visible = True
 
Last edited:
Upvote 0
Solution
well, here you go

VBA Code:
k = 4
Controls("ingredients" & k).Visible = True
Many thanks! if only you knew how many times and different options i tried before asking here! Worked like a dream
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,336
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top