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

Column Scanning – Return Last Not Empty Cell Value (Top to Bottom)

Scans a column in an Excel.Worksheet from top to bottom and returns the value of the last non-empty cell before the first empty cell.

The function iterates downward from the starting row and stops when it encounters the first empty cell, returning the value from the cell directly above it.

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

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

        Return String.Empty
    End Function

Posted by ipercube


© 2026 Ipercube Design