Last column in a particular row

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,402
I have these functions for finding the last row and columns:

Code:
Public Function LRow(ByRef wks As Worksheet) As Long

    On Error GoTo Correction

        With wks
        
            LRow = wks.Cells.Find(What:="*", _
                                  After:=.Cells(.Rows.Count, .Columns.Count), _
                                  SearchDirection:=xlPrevious, _
                                  SearchOrder:=xlByRows).Row
            
        End With
    
Exitpoint:

    On Error GoTo 0
    
    Exit Function
    
Correction:

        LRow = 1

        Resume Exitpoint

End Function

Public Function LRowInCol(ByRef wks As Variant, _
                          ByRef Col As Variant) As Long

    On Error GoTo Correction

        If TypeName(wks) = "String" Then Set wks = Worksheets(wks)

        LRowInCol = wks.Columns(Col).Find(What:="*", _
                                          LookIn:=xlFormulas, _
                                          SearchOrder:=xlRows, _
                                          SearchDirection:=xlPrevious, _
                                          SearchFormat:=False).Row
                                          
Exitpoint:
    
    On Error GoTo 0
    
    Exit Function

Correction:

        LRowInCol = 1
    
        Resume Exitpoint
    
End Function

Public Function LCol(ByRef wks As Worksheet) As Long

    On Error GoTo Correction

        With wks
        
            LCol = .Cells.Find(What:="*", _
                               After:=.Cells(.Rows.Count, .Columns.Count), _
                               SearchDirection:=xlPrevious, _
                               SearchOrder:=xlByColumns).Column
            
        End With
    
Exitpoint:
    
    On Error GoTo 0
    
    Exit Function

Correction:

        LCol = 1
    
        Resume Exitpoint
        
End Function

How can I adapt them to find the last col for a specific row?

Thanks
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,492
Office Version
  1. 365
Platform
  1. Windows
Thanks Mark!
I knew I saw something like that some time ago, just couldn't remember the details.
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,956
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
I typically just use "Long" for everything (and see a lot of other experienced programmers do the same).
Thanks Mark!
I knew I saw something like that some time ago, just couldn't remember the details
You're welcome and I'm the same in as much as I haven't used Integer for a long time (no pun intended).
 

Watch MrExcel Video

Forum statistics

Threads
1,126,956
Messages
5,621,811
Members
415,857
Latest member
braunReivn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top