ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do i run a micro from a formula (https://www.excelbanter.com/excel-discussion-misc-queries/108026-how-do-i-run-micro-formula.html)

Helpme

How do i run a micro from a formula
 
I am trying to write a formula to open the amount of worksheets need when i
input a number.

Seahawk60B

How do i run a micro from a formula
 
Create a loop with the number inputted, let's call it N

For x= 1 to N
sheets.add
Next x


Helpme wrote:
I am trying to write a formula to open the amount of worksheets need when i
input a number.



PCLIVE

How do i run a micro from a formula
 
To add to this:

For x = 1 To InputBox("How many sheets do you want?")
Sheets.Add
Next x


"Seahawk60B" wrote in message
oups.com...
Create a loop with the number inputted, let's call it N

For x= 1 to N
sheets.add
Next x


Helpme wrote:
I am trying to write a formula to open the amount of worksheets need when
i
input a number.





Helpme

How do i run a micro from a formula
 
Both answers were helpfull and very good, i did now explan myself good
enough. i have existing worksheets that i want to stay hidden, unless i need
them, when i input the number only the number of worksheets are opened at
that time.
Thanks

"Helpme" wrote:

I am trying to write a formula to open the amount of worksheets need when i
input a number.


Seahawk60B

How do i run a micro from a formula
 
So if I understand correctly, you don't need to create new worksheets,
but you have worksheets that are hidden that you want to make visible?

The command to make a sheet visible or hidden is:

Sheets("{Name of sheet}").Visible = True
where {Name of sheet} is the name of the sheet - defaults are
Sheet1, Sheet2, etc or
Sheets(1).Visible=True
where 1 is the position of the sheet in the workbook.

To hide sheets, either
ActiveWindow.SelectedSheets.Visible = False
which will hide the currently active sheet, or
Sheets("{Name of sheet}").Visible = False
which will hide the sheet with the name {Name of sheet} -
again, defaults are Sheet1, Sheet2 or
Sheets(1).Visible = False
where 1 is the position of the sheet in the workbook

So depending upon which sheets you want to hide/make visible, you could
try
For x = {Starting sheet #} to {Ending sheet #}
Sheets(x).Visible = True
Next x
where {Ending sheet #} is the number inputted + the value of {Starting
sheet#}

As a side note, sometimes the best way to figure out how to automate
certain things is to record a macro, perform the tasks you want done,
or something similar, and then stop recording and look at the code that
was created by editing the macro.

Also, a more elaborate solution may be to create an initial worksheet
that lists the names of all of the other worksheets, and includes a
check box for each one that would make them visible or hidden as you
toggled each check box.


Helpme wrote:
Both answers were helpfull and very good, i did now explan myself good
enough. i have existing worksheets that i want to stay hidden, unless i need
them, when i input the number only the number of worksheets are opened at
that time.
Thanks

"Helpme" wrote:

I am trying to write a formula to open the amount of worksheets need when i
input a number.




All times are GMT +1. The time now is 05:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com