Macro to insert 2 row and modify

December 6, 2011 at 16:29:09
Specs: Windows XP
Hi All,

I am attempting to build a macro that will insert two rows below any value in column a. I would like the first row to also add the text "NY=Location" and the 2nd row to be blank. I am an intermediate excel user, but not too familar with more complicated macros.

Thank you


See More: Macro to insert 2 row and modify

Report •


#1
December 6, 2011 at 16:37:41
re: "I am attempting to build a macro..."

Does that mean that you have already written some code?

If so, why not post what you've tried and we'll see if we can offer some suggestions.

Please click on the following line before posting any code.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
December 6, 2011 at 18:11:19

The code below adds the two rows. However, I'm not quite sure how get the first row to display a static string of text "Location=NY"

Sub InsertTwoRows_v2()
Dim r As Long
For r = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
Rows(r).Resize(2).Insert
Next
End Sub

Report •

#3
December 6, 2011 at 21:41:30
re: "I'm not quite sure how get the first row to display a static string of text "Location=NY""

I'm guessing you don't want the entire first row to display the string.

Where do you really want the string to be placed?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions

#4
December 7, 2011 at 07:07:34
I'm sorry if I'm not being clear.

For rows in column A, that contain a number greater than 1, I would like the macro to insert two blank rows. Directly under the number in column A, I would like the first row to contain the string "Location=NY" and the second row to be blank.


Report •

#5
December 7, 2011 at 15:45:34
Once again, I'll ask the same question:

Where do you really want the string to be placed?

You said I would like the first row to contain the string "Location=NY"

A row is a series of cells from Column A extending all the way out to the last column in your spreadsheet.

If you want the first row to contain the string "Location=NY" then you are asking for this:


    A           B           C           D          E...   
Location=NY Location=NY Location=NY Location=NY Location=NY etc.

I do not really think that you want the row to contain the string. Maybe you want a specific cell in the Row to contain the string, but not the whole Row...or do you?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#6
December 7, 2011 at 19:16:35
I would like the string to be placed in column A, directly under the number greater than 1, then another row that is blank just below.

Column A --------->Before Column A -------------->After
123456789 123456789
123456789 Location = NY
987654321
555555555 123456789
Location = NY


Report •

#7
December 7, 2011 at 19:38:25
You did not use the pre tags to post your example data so we can't tell how it's supposed to be laid out.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •


Ask Question