+ Reply to Thread
Results 1 to 3 of 3

Last in row

Hybrid View

  1. #1
    Registered User
    Join Date
    06-27-2007
    Posts
    11

    Last in row

    Hello,
    I have two problems to solve.

    First to find last used row in sheet. I was trying looping through column with IsEmpty, but sometimes even if cell is empty and was not touched the result is negative and last row is not really the last one.

    Second. How to print quoation marks in message box?
    example: Msgbox(" he said "" + sentence + """)

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    If you know the the longest column, you can use..

    Cells(65536,MyColumnNumber).end(xlup).row
    ... where MyColumnNumber is the number of the longest column.
    Martin

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    MsgBox (" he said " + """sentence""")

    A few methods to get the row/column

    Sub LastRows_Columns()
    Dim lLR As Long
    Dim iLC As Integer
    
    'find row before next blank cell in column A
    lLR = Range("A1").End(xlDown).Row
    
    'find last used row in column A
    lLR = Cells(Rows.Count, "a").End(xlUp).Row
    
    'find last used row on sheet
    lLR = Cells.Find(what:="*", SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious).Row
    
    lLR = Range("A1").SpecialCells(xlCellTypeLastCell).Row
    
    'find column before next blank cell in row 1
    iLC = Range("A1").End(xlToRight).Column
    
    'find last used column in row 1
    iLC = Cells(1, Columns.Count).End(xlToLeft).Column
    
    'find last used column on sheet
    iLC = Cells.Find(what:="*", SearchOrder:=xlByColumns, _
    SearchDirection:=xlPrevious).Column
    
    iLC = Range("A1").SpecialCells(xlCellTypeLastCell).Column
    
    'set variable to last used cell
    Dim rLC As Range
    Set rLC = ActiveSheet.UsedRange
    
    Set rLC = ActiveCell.SpecialCells(xlLastCell)
    End Sub
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ 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