+ Reply to Thread
Results 1 to 5 of 5

VBA code to autofit columns

  1. #1
    Registered User
    Join Date
    11-22-2012
    Location
    Bangalore, Karnataka, India
    MS-Off Ver
    Excel 2003
    Posts
    7

    Post VBA code to autofit columns

    I have an excel file wherein column J has dropdown values and Column K has a vlookup formula to fetch the values for value in Column K.

    Query:
    1. Users use column J dropdown values to populate the contents. They might choose from 100 different options. So basically a user will use 100 cells in column J. Since column K is formula driven, the appropriate values are auto populated. Wrap text is applied to Column J but the complete text is not shown as the length of the contents are more than 3000 characters.

    Solution required:
    I need the cell to autofit in column J. For Instance, if an user has made a selection in cell K10, then cell J10 should autofit to show the complete text. If he makes a selection in K11, then J11 should autofit.

    I have the same functionality in 2 more columns and hence is proving a headache.

    Regards,
    Amaresh

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: VBA code to autofit columns

    in the worksheet change event (for example sheet1)

    Please Login or Register  to view this content.
    Teach me Excel VBA

  3. #3
    Registered User
    Join Date
    11-22-2012
    Location
    Bangalore, Karnataka, India
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: VBA code to autofit columns

    Thank you Imran but with the code suggested by you, the next time a selection is made in column J, column K is getting auto aligned and column width is increasing and as well row height is shrinking.

    I want the characters in each cell to retain their row height and not shrink.

  4. #4
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: VBA code to autofit columns

    I think you need to autofit rows and not columns

    try this instead
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-22-2012
    Location
    Bangalore, Karnataka, India
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: VBA code to autofit columns

    Thank you Imran.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] vba code for autofit columns in a worksheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-01-2016, 11:11 AM
  2. [SOLVED] Vba code to autofit column when text is entered & time stamp entry for alternating columns
    By m1980rae in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-23-2014, 05:55 AM
  3. VBA code for Autofit Columns in Excel
    By cassiefaye in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2013, 06:40 PM
  4. Autofit all columns
    By cultavix in forum Excel General
    Replies: 2
    Last Post: 11-25-2008, 07:26 AM
  5. [SOLVED] autofit row code
    By Randy Starkey in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-25-2005, 08:06 AM
  6. [SOLVED] Autofit some columns
    By Me in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2005, 05:06 PM
  7. autofit the excel columns
    By cindyxl in forum Excel General
    Replies: 0
    Last Post: 02-09-2005, 12:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1