Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the # of columns from a cell.

Status
Not open for further replies.

Mizzness

Programmer
May 2, 2003
174
US
Can you change the number of columns from the data in a cell ?

Example: If a contract is extended from 3 to 5 years, I would like to extend the number of columns (incl. formulas) from 3 to 5 that are in a seperate tab based on the number (5) that I would input in a seperate cell in a seperate tab.

Thanks for any help.
 
I'm sorry, I got lost at the end of that...could you rephrase?
 
You definitely can do this. Just like ETID, I'm a little unclear as to the specifics, but in general what you are asking is possible.

The change event for a Worksheet object will be generated when you change the cell. Add some code there to alter the other sheets. I suggest you read up in the VBA help files for more specifics on how to create the event handler.

-Venkman

 
I'm sorry for any confusion.
In short, if I change the data of a cell in one tab, I want this to affect the number of columns I have in another tab.

Example: I change the cell number from 3 to 5 this will add 2 columns to my worksheet (formulas incl.)

Is the program the same for adding and deleting ?

Thanks again.
 
You could write it as such. Within the event handler for worksheet_change, have it call a function which takes a number of columns in as a paramater. Set this parameter to whatever the value of the cell you want to check is. This function can then delete or insert columns accordingly.

-Venkman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top