Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

Row Scanning – Return Last Not Empty Cell Value (Left to Right)

Scans a row in an Excel.Worksheet from left to right and returns the value of the last non-empty cell before the first empty cell.

The function stops scanning when it encounters the first empty cell, returning the value of the cell immediately before it.

VB
    Public Function xlL2R_ReturnLastNotEmptyCellValue(wsSheet As Excel.Worksheet,
                                                      ByRef RowNumber As Integer, 
                                                      ByRef ColNumber As Integer) As String

        For iColIndex As Integer = ColNumber To wsSheet.Columns.Count
            If CStr(wsSheet.Cells(RowNumber, iColIndex).Value) = "" Then
                ColNumber = iColIndex - 1
                Return CStr(wsSheet.Cells(RowNumber, ColNumber).Value)
            End If
        Next

        Return String.Empty
    End Function

Posted by ipercube


© 2026 Ipercube Design