VBA Inserting a row

FelixExcel

New Member
Joined
Sep 14, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hey all. Right now I have a command button, which inserts a row at a specific place. In the first cell of the inserted row a text is displayed and at the front of the text a number, which is set by how often the commandbutton has been pressed before. So, the first inserted row will say 1 "Text" in the first cell of that row and the second inserted row will say 2 "Text" in the first cell of that row and so on.

Private Sub CommandButton1_Click()

Sheets("Tabelle1").Range("A17").Select
ActiveCell.EntireRow.Insert Shift:=x1Down

Sheets("Tabelle1").Range("A17").Select
ActiveCell.Value = counter & ". Nachtrag"


The problem I have with this is that because the Rows always get inserted at a fixed place (A17) and shift the other rows down the newest added row is always on top, like this:

3. Text
2. Text
1. Text

Instead I would like them to be like this:

1. Text
2. Text
3. Text

Therefore I want to tell vba that depending on how often the commandbutton has been pressed before the row gets inserted at A17+ Counter. So for example if 2 rows have been added before, the new row will not be inserted at A17 but at A17+2 so A19.

I would appreciate any help.
 

Attachments

  • Unbenannt.PNG
    Unbenannt.PNG
    17.3 KB · Views: 16

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

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