Search for empty cell then return a specific number of cells before it

elsaidmi

New Member
Joined
Mar 19, 2015
Messages
29
Hi, I'm trying to find an empty cell, then return the cell 1 before it, then the cell 2 before it, then the cell 3 before it, so that my summary page is always showing only the last 13 headers. Any idea on what this formula would be?

Thank you in advance!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Two methods using VBA:

Method 1
Code:
Sub findHeaders()
    Dim ws As Worksheet: Set ws = ActiveSheet
    Dim firstEmpty As Range: Set firstEmpty = ws.Columns("B").Find("", [B1], xlValues, xlWhole, xlByRows, xlNext, True)
    Dim var1 As Variant: var1 = Application.Transpose(firstEmpty.Offset(-13, 0).Resize(13, 1).Value2)
End Sub

Or:
Method 2
Code:
Sub findHeaders()
    Dim var1 As Variant: var1 = Application.Transpose(Columns("B").Value2)
    Dim var2(1 To 13) As Variant
    Dim i As Long, j As Long
    For i = LBound(var1) To UBound(var1)
        If IsEmpty(var1(i)) Then
            i = i - 1
            Exit For
        End If
    Next
    For j = LBound(var2) To UBound(var2)
        var2(j) = var1(j + (i - 13))
    Next
End Sub
 
Upvote 0
Assuming that your headers as in row 1 try
Code:
Sub GetHeaders()

   Range("A1").End(xlToRight).Offset(, -13).Resize(1, 13).Copy Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range("A1")

End Sub
Change the sheet name in red to match your summary sheet. The sheet you're copying from needs to be active
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,847
Members
452,361
Latest member
d3ad3y3

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
Back
Top