changing columwidth dynamically
-
Hy everyone! I do want to change the columwidth dynamically, meaning depending on the length of the text/string entered. I had a look in the VBA help but could only find an assignment of fixed values. What I want to do is something similar to Cells(lrow,lcolumn).Width=Length(mystring) But well I guess Excel or VBA respectively is not able to get the length, or does it? :confused: Thanks! Stephan.
-
Hy everyone! I do want to change the columwidth dynamically, meaning depending on the length of the text/string entered. I had a look in the VBA help but could only find an assignment of fixed values. What I want to do is something similar to Cells(lrow,lcolumn).Width=Length(mystring) But well I guess Excel or VBA respectively is not able to get the length, or does it? :confused: Thanks! Stephan.
Rather sad u didn't mention the type of control. Do this by responding to the event that is called anytime the items in the control change. Just loop through all the items in the control and get the maximum width to the lengthiest string.
-
Rather sad u didn't mention the type of control. Do this by responding to the event that is called anytime the items in the control change. Just loop through all the items in the control and get the maximum width to the lengthiest string.
I do not use any control. I do want to calculate using data from one sheet in Excel and printing the results to another sheet. Then I do want to change the cellsize to make it fit to it's contains. So what I want to do is implement the same function which you get by sizing a column to optimal size in Excel. And because I do not know which strings or integers will be copied to the sheet (meaning as result) I do want to print the data to the sheet and change the size afterwards. Thanks. Stephan.
-
I do not use any control. I do want to calculate using data from one sheet in Excel and printing the results to another sheet. Then I do want to change the cellsize to make it fit to it's contains. So what I want to do is implement the same function which you get by sizing a column to optimal size in Excel. And because I do not know which strings or integers will be copied to the sheet (meaning as result) I do want to print the data to the sheet and change the size afterwards. Thanks. Stephan.
I found a solution. To get the optimal size of the cell in Excel via VBA you have to use the .autofit operation syntax
Columns(index).Autofit
This is the easiest solution! Stephan.