VBA code help

Good Morning, I am working on a VBA code to autofit, I am using a dropdown list and some of the wording is to long, so i added autofit. The code is working fine when i press the play button, but i want it to change automatcially when I select. Pleaes see code I hope that someone can help me.

Option Explicit
Public Sub AutoFitAll()
Dim mw As Single
Dim cM As Range
Dim rng As Range
Dim cw As Double
Dim rwht As Double
Dim ar As Variant
Dim i As Integer

With Sheet2
    Application.ScreenUpdating = False
        ar = Array(“A52”, “A53”, “A54”, “A55”, “A56”, “A57”, “A58”, “A59”, “A60”, “A61”)
   
    For i = 0 To UBound(ar)
    On Error Resume Next
    Set rng = Range(Range(ar(i)).MergeArea.Address)
    rng.MergeCells = False
    cw = rng.Cells(1).ColumnWidth
    mw = 0
    For Each cM In rng
    cM.WrapText = True
    mw = cM.ColumnWidth + mw
    Next
    mw = mw + rng.Cells.Count * 0.66
    rng.Cells(1).ColumnWidth = mw
    rng.EntireRow.AutoFit
    rwht = rng.RowHeight
    rng.Cells(1).ColumnWidth = cw
    rng.MergeCells = True
    rng.RowHeight = rwht
    Next i
    Application.ScreenUpdating = True
End With
End Sub

By: Babb

189 thoughts on “VBA code help

  1. supreme clothing

    I really wanted to develop a remark to be able to express gratitude to you for those splendid facts you are giving out at this site. My long internet research has now been compensated with extremely good strategies to write about with my companions. I would state that that many of us visitors are extremely lucky to exist in a fine website with many special individuals with insightful solutions. I feel rather lucky to have encountered the webpage and look forward to so many more exciting minutes reading here. Thanks a lot once again for everything.

  2. best cbd gummies

    Usually I don at read post on blogs, but I would like to say that this write-up very forced me to try and do so! Your writing style has been amazed me. Thanks, quite nice post.

  3. poachtapp.com

    Wow, marvelous blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your site is great, let alone the content!

  4. yeezy

    I precisely desired to say thanks yet again. I am not sure the things that I might have sorted out in the absence of the entire information discussed by you concerning such a question. It had been a traumatic condition in my position, however , encountering a expert approach you processed it took me to cry with gladness. I am just happier for the guidance and thus hope you find out what a great job you were putting in instructing some other people with the aid of your webblog. More than likely you haven’t met all of us.

  5. lebron 17 shoes

    I must show my appreciation to this writer just for rescuing me from this type of condition. After exploring through the the web and meeting advice that were not helpful, I assumed my life was done. Existing minus the answers to the problems you’ve solved through your entire post is a serious case, as well as ones which could have badly affected my career if I hadn’t come across your blog. Your natural talent and kindness in controlling a lot of stuff was tremendous. I don’t know what I would’ve done if I hadn’t come upon such a subject like this. I am able to at this time relish my future. Thanks very much for the professional and results-oriented help. I won’t be reluctant to suggest your blog post to anyone who desires guide about this problem.

  6. Best CBD Oil

    whoah this blog is great i love reading your articles. Keep up the great work! You know, a lot of people are searching around for this info, you can help them greatly.

  7. nike huarache

    I would like to express my gratitude for your generosity giving support to men who must have help with that situation. Your real commitment to passing the message around was surprisingly effective and has consistently encouraged regular people just like me to realize their ambitions. Your new informative tips and hints means a lot a person like me and a whole lot more to my office colleagues. Thank you; from each one of us.

  8. Kala Krysh

    The wind is blowing my hair softly, and the leaves are gently floating beside you. Looking at the blue sky, sitting on the green grass, so warm and harmonious. I really want to stop this moment and let us be happy together for a lifetime!

Leave a Reply

Your email address will not be published. Required fields are marked *