Set header to row 2

alialeola

New Member
Joined
Jul 6, 2022
Messages
21
Platform
  1. Windows
Hi guys,

I am VBA level -1 and I need help with the below.

The macro should bring excel header on row 2, with these 2 possible scenarios:
- insert 1 blank row if there is data on row 1
- if there are several blank rows above the data, keep just 1 of them

Hoping it's clear, could you pls pls pls assist?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Perhaps something like this?
VBA Code:
Sub HeaderMacro()

    Dim FirstRow As Long
    
'   Check to see if data in cell A1 and if not, insert row
    If Range("A1") <> "" Then
        Rows(1).Insert
    Else
'       Find first row with data in column A
        FirstRow = Range("A1").End(xlDown).Row
'       Delete rows if FirstRow greater than 2
        If FirstRow > 2 Then
            Rows("2:" & FirstRow - 1).Delete
        End If
    End If
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,220
Messages
6,123,697
Members
449,117
Latest member
Aaagu

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