$show=home$hide=mobile-page

Excel Function to find Last Column in a Row

Excel custom function to find last column in the specified row. Function can return last column number, last column content and last column address.

Excel custom function to find last column in the specified row. Function can return last column number, last column content and last column address
Excel custom function to find last column in the specified row.
Function can return last column number, last column content and last column address.
Function Name LastColumnInRow(row_no, sheet_name, Optional dtype)
Function Description Excel Function to find Last Column in a Row
Data Parameters row_no:- Specify the row number
sheet_name:- Specify the name of the sheet
dtype:- 0 to return column number, 1 to return last column content, 2 to return last column address

'-----------------------------------------------------------------------------------------------------------------------------------------
'Function Name                    : LastColumnInRow(col_no, sheet_name, Optional dtype = 0)
'Function Description             : Excel Function to find Last Column in a Row
'Data Parameters                  : row_no:- Specify the row number
'                                   sheet_name:- Specify the name of the sheet
'                                   dtype:- 0 to return column number, 1 to return last column content, 2 to return last column address
'-----------------------------------------------------------------------------------------------------------------------------------------
Public Function LastColumnInRow(row_no, sheet_name, Optional dtype)
    With Worksheets(sheet_name)
        LastCol = .Cells(row_no, .Columns.Count).End(xlToLeft).Column
    End With    
    Select Case dtype
    Case 0
        LastColumnInRow = LastCol
    Case 1
        LastColumnInRow = Range(Split(Cells(, LastCol).Address, "$")(1) & row_no).Value
    Case 2
        LastColumnInRow = Replace(Range(Split(Cells(, LastCol).Address, "$")(1) & row_no).Address, "$", "")
    Case Else
        LastColumnInRow = LastCol
    End Select
End Function

Function Usage

Example usage of excel function to get Last Column in a row
Example usage of excel function to get Last Column in a row

To return Last Column Number
=LastColumnInRow(1, "Sheet1", 0)

To return Last Column Value
=LastColumnInRow(1, "Sheet1", 1)

To return Last Column Address
=LastColumnInRow(1, "Sheet1", 2)

COMMENTS





Name

AngularJS,3,Automation Testing,8,CSharp,5,Disqus,1,Excel,2,HP ALM,5,HTML5,1,ISTQB,2,Java Script,2,Manual Testing,7,Photography,1,Quiz,2,REST API,5,Testing,15,UFT,8,VB,5,VBScript,1,Wordpress,1,
ltr
item
Aneejian: Excel Function to find Last Column in a Row
Excel Function to find Last Column in a Row
Excel custom function to find last column in the specified row. Function can return last column number, last column content and last column address.
https://3.bp.blogspot.com/-0B0jght2qGs/WMjpJRCx2tI/AAAAAAAAAFc/iC5FoCO4g50Krde65aU3H9D5jIIK2FUfgCPcB/s320/excel-function-to-find-last-column-in-a-row.jpg
https://3.bp.blogspot.com/-0B0jght2qGs/WMjpJRCx2tI/AAAAAAAAAFc/iC5FoCO4g50Krde65aU3H9D5jIIK2FUfgCPcB/s72-c/excel-function-to-find-last-column-in-a-row.jpg
Aneejian
http://www.aneejian.com/2012/11/excel-function-to-find-last-column-in-a-row.html
http://www.aneejian.com/
http://www.aneejian.com/
http://www.aneejian.com/2012/11/excel-function-to-find-last-column-in-a-row.html
true
5798203121010168414
UTF-8
Loaded All Posts No posts found VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU ARCHIVE SEARCH ALL POSTS No post found which matches with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy