+ Reply to Thread
Results 1 to 7 of 7

Please help! formatting last row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-04-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    127

    Please help! formatting last row

    Can someone please help me with the next peice of code required for this:

    I want to go to the last row of the sheet and add some BOLD and Colour formatting.

    the TOTALS range is C26:X26 (although the amount of rows change on a daily basis)

    I have all the code working, and have got as far as:

     With Sheets("Sheet1")
                 .Range("C" & .Rows.Count).End(xlUp).Select
                  ActiveCell.Offset(0, -1) = "Turnover"
        
               End With
    Which adds "Turnover" into cell B**, I then want to format the subtotals to BOLD and highlight the cells as GREY.


    Can anyone help please?


    thankyou.
    Last edited by Robotacha2010; 04-15-2011 at 08:21 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Please help! formatting last row

    Like this:

    With Sheets("Sheet1")
        With .Range("C" & .Rows.Count).End(xlUp)
            .Offset(0, -1) = "Turnover"
            With .Resize(1, 22)
                .Font.Bold = True
                .Interior.ColorIndex = 15
            End With
        End With
    End With

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Contributor
    Join Date
    12-04-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    127

    Re: Please help! formatting last row

    thankyou greatly.

    Can you just answer 1 more question for me please?

    where you have

    .resize(1,22)
    where 22 refers to the column (X), what is the '1' doing?

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Please help! formatting last row

    This refers to the range C26:

    With .Range("C" & .Rows.Count).End(xlUp)

    This resizes the range being referred to 1 row tall (same as it already is) and 22 columns wide (across to X):

    .resize(1,22)

    Dom

  5. #5
    Forum Contributor
    Join Date
    12-04-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    127

    Re: Please help! formatting last row

    thankyou.

    hate askign questions, and I am learning from everything Im told,

    Could you possibly add a little more code for me?

    I want these newly formatted cells, to also have borders?

    I have tried:

    With Sheets("Sheet1")
         With .Range("C" & .Rows.Count).End(xlUp)
            .Offset(0, -1) = "Turnover"
            .Font.Bold = True
                 With .Resize(1, 22)
                 .Font.Bold = True
                 .Interior.ColorIndex = 15
                    With Selection.Borders(xlEdgeBottom)
                        .LineStyle = xlContinuous
                        .Weight = xlMedium
                        .ColorIndex = xlAutomatic
                   End With
                 End With
             End With
          End With

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Please help! formatting last row

    You were nearly there, just didn't need the selection bit:

    With Sheets("Sheet1")
         With .Range("C" & .Rows.Count).End(xlUp)
            .Offset(0, -1) = "Turnover"
            .Font.Bold = True
                 With .Resize(1, 22)
                 .Font.Bold = True
                 .Interior.ColorIndex = 15
                    With .Borders(xlEdgeBottom)
                        .LineStyle = xlContinuous
                        .Weight = xlMedium
                        .ColorIndex = xlAutomatic
                    End With
                 End With
        End With
    End With

    Try and get using Select and Activate out of your head when writing vba code. They are the manual actions that you perform when working on a spreadsheet and as such if you use the macro recorder it translates them into code but they are not needed and best avoided.

    Dom

  7. #7
    Forum Contributor
    Join Date
    12-04-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    127

    Re: Please help! formatting last row

    Again, sincere thanks!

    I can now add this macro button to a colleagues computer, schedule the raw data speradsheet to be emailed to him, and he can do the work himself! now saving me 15 minutes each day :D

    all thanks to you.

    regards,

    "a happy" Michael.

+ 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