To insert a new row after the last active row along with increment the column value ?

reach2vj

New Member
Joined
Mar 7, 2011
Messages
3
Hi All,

Am novice to excel, am trying to insert a new row aftert the last active row and at the same time i need to increment the column value to the newly added row.

ex :

<table width="588" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"> <col style="width: 169pt;" width="225"> <col style="width: 110pt;" width="146"> <col style="width: 115pt;" width="153"> <tbody><tr style="height: 25.5pt;" height="34"> <td class="xl67" style="height: 25.5pt; width: 48pt;" width="64" height="34">TC#</td> <td class="xl67" style="border-left: medium none; width: 169pt;" width="225">
Test Execution Steps</td> <td class="xl67" style="border-left: medium none; width: 110pt;" width="146">
Expected Result</td> <td class="xl67" style="border-left: medium none; width: 115pt;" width="153">Actual Result</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl68" style="height: 12.75pt; width: 48pt;" width="64" align="right" height="17">1
</td> <td class="xl65" style="border-top: medium none; width: 169pt;" width="225">abc</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 110pt;" width="146">abc</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 115pt;" width="153">xxx</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl68" style="height: 12.75pt; width: 48pt;" width="64" align="right" height="17">2
</td> <td class="xl65" style="border-top: medium none; width: 169pt;" width="225">abc</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 110pt;" width="146">abc</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 115pt;" width="153">xxx</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl68" style="height: 12.75pt; width: 48pt;" width="64" align="right" height="17">3
</td> <td class="xl65" style="border-top: medium none; width: 169pt;" width="225">abc</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 110pt;" width="146">abc</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 115pt;" width="153">xxx</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl69" style="height: 12.75pt; border-top: medium none; width: 48pt;" width="64" align="right" height="17">
</td><td class="xl65" style="border-top: medium none; width: 169pt;" width="225">
</td><td class="xl65" style="border-top: medium none; border-left: medium none; width: 110pt;" width="146">
</td><td class="xl65" style="border-top: medium none; border-left: medium none; width: 115pt;" width="153">
</td></tr><tr style="height: 12.75pt;" height="17"><td class="xl69" style="height: 12.75pt; border-top: medium none; width: 48pt;" width="64" align="right" height="17">
</td><td class="xl65" style="border-top: medium none; width: 169pt;" width="225">
</td><td class="xl65" style="border-top: medium none; border-left: medium none; width: 110pt;" width="146">
</td><td class="xl66" style="border-top: medium none; width: 115pt;" width="153">
</td></tr></tbody></table><table width="1097" border="0" cellpadding="0" cellspacing="0"><tbody><tr style="height: 25.5pt;" height="34"><td class="xl68" style="height: 25.5pt; width: 28pt;" width="37" height="34">
</td> <td class="xl68" style="border-left: medium none; width: 155pt;" width="207">Now, here i want to insert new row after row 3 and have to increment the column value (TC#) to 4 after clicking on InsertNewRow button.

Macro Code used :
<Code>
Sub InsertNewRow ()
ActiveCell.Offset(Selection.Rows.Count, 0).EntireRow.Insert
End Sub

Can anyone help me on this .....

Many Thanks,
BobR
</td> <td class="xl68" style="border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl68" style="border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl68" style="border-left: medium none; width: 35pt;" width="46">
</td> <td class="xl68" style="border-left: medium none; width: 55pt;" width="73">
</td> <td class="xl68" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl68" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl69" style="border-left: medium none; width: 161pt;" width="214">
</td> </tr> <tr style="height: 13.5pt;" height="18"> <td colspan="9" class="xl81" style="height: 13.5pt;" height="18">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl71" style="height: 12.75pt; width: 28pt;" width="37" align="right" height="17">
</td> <td class="xl65" style="width: 155pt;" width="207">
</td> <td class="xl65" style="border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl67" style="width: 35pt;" width="46">
</td> <td class="xl72" style="border-left: medium none; width: 55pt;" width="73">
</td> <td class="xl73" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl74" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl75" style="border-top: medium none; border-left: medium none; width: 161pt;" width="214">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl71" style="height: 12.75pt; width: 28pt;" width="37" align="right" height="17">
</td> <td class="xl65" style="border-top: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl67" style="border-top: medium none; width: 35pt;" width="46">
</td> <td class="xl72" style="border-left: medium none; width: 55pt;" width="73">
</td> <td class="xl73" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl74" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl76" style="border-left: medium none; width: 161pt;" width="214">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl71" style="height: 12.75pt; width: 28pt;" width="37" align="right" height="17">
</td> <td class="xl65" style="border-top: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl67" style="border-top: medium none; width: 35pt;" width="46">
</td> <td class="xl72" style="border-left: medium none; width: 55pt;" width="73">
</td> <td class="xl73" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl74" style="border-left: medium none; width: 40pt;" width="53">
</td> <td class="xl76" style="border-left: medium none; width: 161pt;" width="214">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl71" style="height: 12.75pt; width: 28pt;" width="37" align="right" height="17">
</td> <td class="xl65" style="border-top: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl67" style="border-top: medium none; width: 35pt;" width="46">
</td> <td class="xl72" style="border-left: medium none; width: 55pt;" width="73">
</td> <td class="xl73" style="border-left: medium none; width: 40pt;" width="53"> </td> <td class="xl74" style="border-left: medium none; width: 40pt;" width="53"> </td> <td class="xl76" style="border-left: medium none; width: 161pt;" width="214"> </td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl77" style="height: 12.75pt; border-top: medium none; width: 28pt;" width="37" align="right" height="17">
</td> <td class="xl65" style="border-top: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl78" style="border-top: medium none; width: 35pt;" width="46">
</td> <td class="xl79" style="border-top: medium none; border-left: medium none; width: 55pt;" width="73">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 40pt;" width="53"> </td> <td class="xl74" style="border-left: medium none; width: 40pt;" width="53"> </td> <td class="xl80" style="border-top: medium none; border-left: medium none; width: 161pt;" width="214"> </td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl77" style="height: 12.75pt; border-top: medium none; width: 28pt;" width="37" align="right" height="17">
</td> <td class="xl65" style="border-top: medium none; width: 155pt;" width="207">
</td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 155pt;" width="207">
</td> <td class="xl67" style="border-top: medium none; width: 155pt;" width="207">
</td> <td class="xl78" style="border-top: medium none; width: 35pt;" width="46"> </td> <td class="xl79" style="border-top: medium none; border-left: medium none; width: 55pt;" width="73"> </td> <td class="xl65" style="border-top: medium none; border-left: medium none; width: 40pt;" width="53"> </td> <td class="xl74" style="border-left: medium none; width: 40pt;" width="53"> </td> <td class="xl80" style="border-top: medium none; border-left: medium none; width: 161pt;" width="214"> </td> </tr> </tbody></table>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
try this

Code:
Sub InsertNewRow()
Dim LR As Long
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Cells(LR, 1).Offset(1, 0).EntireRow.Insert
Cells(LR, 1).Copy Destination:=Cells(LR, 1)
Cells(LR + 1, 1).Value = Cells(LR, 1) + 1
End Sub
 
Upvote 0
Hi There,

Thanks for quick reply, i run the code but it gave this error :

Run-time Error'1004':
Cannot change part of the mereged cell.

When i clicked on debug button,

the below code was getting highlighted :
<code>
Cells(LR, 1).Copy Destination:=Cells(LR, 1)
</Code>
Note : for reference LR value was 99

Thanks,
Bobr
 
Upvote 0
Hi There,

Thanks for quick reply, i run the code but it gave this error :

Run-time Error'1004':
Cannot change part of the mereged cell.

When i clicked on debug button,

the below code was getting highlighted :
<code>
Cells(LR, 1).Copy Destination:=Cells(LR, 1)
</code>
Note : for reference LR value was 99

Thanks,
Bobr
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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