+ Reply to Thread
Results 1 to 7 of 7

Find last row with data and autofit, bold and center align

Hybrid View

daillest319 Find last row with data and... 02-23-2012, 12:54 PM
Charles Re: Find last row with data... 02-23-2012, 02:28 PM
arlu1201 Re: Find last row with data... 02-23-2012, 02:37 PM
daillest319 Re: Find last row with data... 02-23-2012, 03:03 PM
Charles Re: Find last row with data... 02-23-2012, 04:51 PM
arlu1201 Re: Find last row with data... 02-24-2012, 02:34 AM
daillest319 Re: Find last row with data... 02-24-2012, 11:32 AM
  1. #1
    Registered User
    Join Date
    01-09-2012
    Location
    here
    MS-Off Ver
    Excel 2003
    Posts
    68

    Find last row with data and autofit, bold and center align

    i need a macro to Find last row with data and autofit, bold and center align all the cells in the row
    Last edited by daillest319; 02-24-2012 at 11:32 AM.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Find last row with data and autofit, bold and center align

    daillest319,

    Here's a simple code that may help you.

    Sub Format_LastRow()
    Application.ScreenUpdating = False
    Dim lrow As Long
    lrow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
    Range("A2:G" & lrow).Select
        With Selection
            .HorizontalAlignment = xlCenter
        End With
        With Selection.Font
            .FontStyle = "Bold"
        End With
        Columns("A:A").EntireColumn.AutoFit
    
    End Sub
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Find last row with data and autofit, bold and center align

    To find the last row of column A - you can use this code line
     Dim lrow as long
    lrow = worksheets("Sheet1").range("A" & rows.count).end(xlup).row
    To autofit -
     Cells.entirecolumn.autofit
    To bold and center align, all you need to do is just record the action and you will get the code.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    01-09-2012
    Location
    here
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Find last row with data and autofit, bold and center align

    Thanks i started using this code but cant seem to figure out how to make not only look just in column A but in all columns for the last row becuase some of the cells have empty data. For example the last row had A,B,C etc blank and the data starts at column G.



        Dim lngLastRow As Long
    
        'Range("A1").Select
        'Range(Selection, Selection.End(xlDown)).Select
    
        Range("A1").End(xlDown).Select
    
        lngLastRow = ActiveCell.Row
    
        Rows(lngLastRow).Select
    
        Selection.Font.Bold = True
        Cells(lngLastRow, "A").Select

  5. #5
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Find last row with data and autofit, bold and center align

    Hi,

    Your code

     Dim lngLastRow As Long
    
        'Range("A1").Select
        'Range(Selection, Selection.End(xlDown)).Select
    
        Range("A1").End(xlDown).Select
    
        lngLastRow = ActiveCell.Row
    
        Rows(lngLastRow).Select
    
        Selection.Font.Bold = True
        Cells(lngLastRow, "A").Select
    Try

     Dim lngLastRow As Long
    
        'Range("A1").Select
        'Range(Selection, Selection.End(xlDown)).Select
    
        Range("A1").End(xlDown).Select
    
        lngLastRow = ActiveCell.Row
        range("A"& lngLasRow & ":G" & lngLasRow).select
        'Rows(lngLastRow).Select
    
        Selection.Font.Bold = True
        'Cells(lngLastRow, "A").Select
    But the code provided my myself and arlu1201 should do the job.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Find last row with data and autofit, bold and center align

    You can also use this -
     lrow = ActiveSheet.UsedRange.Rows.Count
    You can also specify the sheet instead of Activesheet.

  7. #7
    Registered User
    Join Date
    01-09-2012
    Location
    here
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Find last row with data and autofit, bold and center align

    thank you all for all yuor help

+ 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