![]() This is what I want the display to look like: A B C How can I do AutoFit on each cell of the second row in each worksheet? Above code failing to autofit data from my second row. With the above code, the data is then displayed as follows: A B C Note that "Jhon is the best employee" is all in one cell (A1) but when displayed its contents overlap cells B1 and C1. I am trying to do AutoFit cells in the range A2 to AA2.īelow is the code I am trying: Application.ScreenUpdating = FalseĬells.Range("A2:AA2").EntireColumn.AutoFitīelow is some sample Excel data, as displayed on the screen: A B C This should be enough to get you on the right track. ![]() You can also include all rows all the way down to the bottom of the sheet like this: wkBk.Range(Range("A2"), Cells(, "AA")).Columns.AutoFit The above assumes that row 999 is your last row with data to be autofitted. ![]() This requires only a simple modification: wkBk.Range("A2:AA999").Columns.AutoFit wkBk.Range("A2:AA2").Columns.AutoFitĮDIT You now want to do AutoFit not only for row 2, but also 3, 4, 5 etc. Instead of doing Autofit on EntireColumn, do it on Columns. One way to do it would be to store the content of the first row, delete it, autofit and insert the content of the first row back: Public Sub test()įor Each wkBk In ActiveWorkbook.Worksheets If what you want is to force Autofit to ignore the first row and only Autofit based on the content of rows 2 and greater.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |