ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA code to add rows (https://www.excelbanter.com/excel-discussion-misc-queries/34919-vba-code-add-rows.html)

Kiran

VBA code to add rows
 
Can anyone let me know the code to add rows on a button click.
Thnx

FSt1

hi,
To add a row to the sheet.....
Rows("6:6").Select
Selection.Insert Shift:=xlDown

To add a row to a range.........
Range("A6:I6").Select
Selection.Insert Shift:=xlDown

FSt1

"Kiran" wrote:

Can anyone let me know the code to add rows on a button click.
Thnx


Kiran

Hi FST1,
thanks for replying. But I does not solve, what this code is doing is moving
the data from the selected row. I dont want to move data. When I click the
Get me a New Row button, I want to generate a new row.
So basically automating
Right-click - Insert Row below the selected cell.

Hope i was clearer this time

"FSt1" wrote:

hi,
To add a row to the sheet.....
Rows("6:6").Select
Selection.Insert Shift:=xlDown

To add a row to a range.........
Range("A6:I6").Select
Selection.Insert Shift:=xlDown

FSt1

"Kiran" wrote:

Can anyone let me know the code to add rows on a button click.
Thnx


FSt1

hi,
the code is adding a row. it has to "move" the data to add the row.
If you want the row added below certain data, then select the cell below the
data then run the code.
example:
You have data on row 6 and wish to add a row below it.
Click anywhere on row 7

Selection.entirerow.Insert Shift:=xlDown

FSt1

"Kiran" wrote:

Hi FST1,
thanks for replying. But I does not solve, what this code is doing is moving
the data from the selected row. I dont want to move data. When I click the
Get me a New Row button, I want to generate a new row.
So basically automating
Right-click - Insert Row below the selected cell.

Hope i was clearer this time

"FSt1" wrote:

hi,
To add a row to the sheet.....
Rows("6:6").Select
Selection.Insert Shift:=xlDown

To add a row to a range.........
Range("A6:I6").Select
Selection.Insert Shift:=xlDown

FSt1

"Kiran" wrote:

Can anyone let me know the code to add rows on a button click.
Thnx


PegL

Now I'm not sure what you're really trying to do. The code FST1 provided
inserts a row above row 6. You'd obviously modify it to insert where you
want it. If you want to insert after a certain location, simply reference
the cell below it. Technically, you can't add a row in Excel. It has 65536
rows, period.

"Kiran" wrote:

Hi FST1,
thanks for replying. But I does not solve, what this code is doing is moving
the data from the selected row. I dont want to move data. When I click the
Get me a New Row button, I want to generate a new row.
So basically automating
Right-click - Insert Row below the selected cell.

Hope i was clearer this time

"FSt1" wrote:

hi,
To add a row to the sheet.....
Rows("6:6").Select
Selection.Insert Shift:=xlDown

To add a row to a range.........
Range("A6:I6").Select
Selection.Insert Shift:=xlDown

FSt1

"Kiran" wrote:

Can anyone let me know the code to add rows on a button click.
Thnx



All times are GMT +1. The time now is 02:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com