• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to insert a row into median range of cells

Octofez2

New Member
Hello all,

What I am looking for is some code that could insert a row based on a median range. The sample included has some data that stays consistent.

Please rename the attachment as .xlsx For some reason I had no visibility to any excel files for an upload option.

Thank you.
 

Attachments

Last edited:
Hi ,

I have understood nothing ; can you explain in more detail , and upload a workbook which has more realistic data ?

Narayan
 
My apologies Narayank..

What I would like to do is have a macro insert a blank row into within a range. You will see in Sheet1 that the total between A5:A15 is 11 but on Sheet2 the total between A5:A26 is 22. My data is dynamic and in the sample both sheets have a row inserted where I would like it in the Final Result.
 

Attachments

Both the following require you to select a range (ideally the data body range but it's up to you) on the sheet before running the code. The first will insert entire rows into the spreadsheet:
Code:
Sub blah()
Rows(Int(Selection.Row + Selection.Rows.Count / 2)).Insert
End Sub

The second will insert cells only as wide as the original selected range.
Code:
Sub blah2()
Selection.Offset(Int(Selection.Rows.Count / 2)).Resize(1).Insert shift:=xlDown
End Sub
 
Truly amazing with one line of code and it works great. I can't thank you enough. I spent countless hours searching and trying different code. Thank you p45cal for your time.
 
Back
Top