+ Reply to Thread
Results 1 to 3 of 3

Automatically auto-fit column width upon data entry.

  1. #1
    Registered User
    Join Date
    12-29-2012
    Location
    Hawaii
    MS-Off Ver
    Excel 2010
    Posts
    3

    Automatically auto-fit column width upon data entry.

    Private Sub Workbook_SheetChange(ByVal Sh As Object, _
    ByVal Target As Range)
    Dim actCol, curCol
    actCol = Target.Column
    If actCol > 52 Then
    curCol = Chr(Int((actCol - 1) / 52) + 64) & _
    Chr(Int((actCol - 27) / 26) + 64) & _
    Chr(Int((actCol - 27) Mod 26) + 65)
    ElseIf actCol > 26 Then
    curCol = Chr(Int((actCol - 1) / 26) + 64) & _
    Chr(Int((actCol - 1) Mod 26) + 65)
    Else
    curCol = Chr(actCol + 64)
    End If
    Columns(curCol & ":" & curCol).AutoFit
    End Sub

    My data entry guys are not to be trusted to touch anything other than putting stuff in the cell. So the simpler I make it for them, the better. Auto-fitting column width has been an issue. They constantly print things out with ##### in a cell...sigh. So, with any excel issue I can't figure out I turn to the guru's. I found the afore mentioned Russian rocket surgery schematics on the intarweb. It appears to do what I need just fine....
    However, I have some drop down lists in the workbook, and now said drop downs give me an error code 1004. I can clear it and move on, but, I'd rather not get that when the data entry monkeys are futzing with it. Second, it appears that Ctrl-z no longer functions with this macro floating in the VBA world.
    I consider myself fairly savvy on excel for all things NOT code. So before I get responses with add so-n-so to the what's-it line, I need to say, I'm exceedingly good at cutting and pasting code from the web to the VBA world... And that's as far as my Greek translation goes.
    Any help would be appreciated.
    Thanks
    -Gray

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Automatically auto-fit column width upon data entry.

    This must be put on the sheet itself....not in the module section of the weekend....HTH...

    Private Sub Worksheet_Change(ByVal Target As Range)

    Columns(Target.Column).EntireColumn.AutoFit

    End Sub
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Automatically auto-fit column width upon data entry.

    that should have been Worksheet not weekend....obviously my mind was somewhere else....

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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