Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. changing columwidth dynamically

changing columwidth dynamically

Scheduled Pinned Locked Moved Visual Basic
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephan Wright
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • S Stephan Wright

      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.

      M Offline
      M Offline
      magnifique
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • M magnifique

        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.

        S Offline
        S Offline
        Stephan Wright
        wrote on last edited by
        #3

        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.

        S 1 Reply Last reply
        0
        • S Stephan Wright

          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.

          S Offline
          S Offline
          Stephan Wright
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups