5

I am looking to insert a new row below a frozen header row at the top of a spreadsheet. The issue I face is the amount of rows in the header is ever changing but I always want the row to be inserted at the first line below the header. Is there a flag in the row that says its frozen? which I could just count the amount of rows with said flag, add 1 and insert row. Any help would be very helpful.

Matt

2
  • When you say frozen, do you mean you used ActiveWindow.FreezePanes (in VBA), or View | Freeze Panes | Freeze Panes (from the ribbon). Or do you mean Split where you have multiple scrollable views of the same spreadsheet in the same window? Commented May 14, 2015 at 16:29
  • I mean View | Freeze Panes | Freeze top row, From the ribbon Commented May 14, 2015 at 16:38

2 Answers 2

6

If you are using FreezePanes then I think you go this route:

Sub InsertRowBelowHeader()
    Rows(ActiveWindow.Panes(1).VisibleRange.Rows.Count + 1).Insert
End Sub

Before, the freeze line is below row 5. Freeze pane was done on cell A6

before

After, a row is added to split a/b

after

Here is a relevant discussion which came up on Google for freeze panes and VBA. http://www.mrexcel.com/forum/excel-questions/275645-identifying-freeze-panes-position-sheet-using-visual-basic-applications.html

Sign up to request clarification or add additional context in comments.

5 Comments

Excellent! ActiveWindow.Panes(1).VisibleRange.Rows.Count + 1 will give you the row number below the freeze line.
My terminology might be incorrect, all this does is inserts a line in the header and increases the amount of rows the header contains by 1
When I run that code on my end, it adds the row below the freeze line. Maybe add a picture to your post so we can see what we're dealing with?
Your answer solved the question OP asked. His acceptance of the other answer indicates that wasn't the question he meant to ask...
At least I learned how to access VisibleRange... that's new.
3

Here you are!

Sub InsertRowBelowHeader()
    Rows(ActiveWindow.SplitRow + 1).Insert
End Sub

5 Comments

Close, but possibly no cigar. The OP asked about .FreezePane which is different and can be set independently of Split. If he's really talking about SplitPanes you nailed it, if not, I don't think it can be done.
That just inserts a row at the top of the page inside the header and shifts everything in the header down. I need to add a row outside of the header
All I did was go to View > Freeze pane > Freeze top row in excel and then inserted rows on top of that header. I just want to use VBA to along with other things insert a row right below the "header" frozen row. The thing is the amount of rows in the header is always changing but I want the row always inserted right after the header.
I reproduced all actions you described, then launched the code, and I've got a row inserted below the frozen rows. I'm on Excel 2007 Win7 x64.
Okay, This worked, I must of had an old piece of code still in there that was inserting a row at the top. Thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.