+ Reply to Thread
Results 1 to 3 of 3

Do until last row

Hybrid View

  1. #1
    Registered User
    Join Date
    01-07-2011
    Location
    Stamford, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Do until last row

    I've been trying to work out how to format cells until the last cell that has data in and then stop. I have written the code for the formatting but just need some help with making it run until the last cell with a value in it. I would prefer it in this format.

    Sub Vibration()
    Dim i as Long
    i=0
    For i = 57 to (code for last cell with value in it here)
    
    #FORMATTING CODE#
    
    next i
    End Sub
    The column, if needed, is BA.
    Thanks

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Do until last row

    Hi,

    There's no need to loop, you can set a variable to the range containing data.

    Sub a()
    Dim r As Range
    Set r = Range(Range("B57"), Range("B" & Rows.Count).End(xlUp))
    r.Interior.ColorIndex = 3
    End Sub
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    01-07-2011
    Location
    Stamford, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Do until last row

    I really needed it to loop as i have many if statments specific to the cell being formatted within the loop.
    I've managed to do it myself though.

    Dim i as Long
    i = 57
    With Sheets("Design Database")
        Do While i <= .Rows.Count
        If .Cells(i, 2) <> "" Then
    
    
    #FORMATTING#
    
        Else
        Exit Do
        End If
        i = i + 1
        Loop
        End With

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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