Adding and deleting row in dynamic range VBA

tybalt

New Member
Joined
May 19, 2011
Messages
17
Hi Gurus

I have a dynamic range "Employees" that is made with the offset and counta functions. It goes from A1:C1 and down to the first empty cell before A20:C20.

The column headings are age, gender, salary

I am creating a userform which I can add new people, or change people's details, or delete them.

I'm really struggling to figure out how I can delete someone in the list (maybe in the middle of the list) but I do NOT want to delete the entire row - just the row from Ax:Cx. When I delete that entry, I would like the entries below to shift up, but I also want the dynamic range parameters to stretch down to A20:C20. This is because I have other tables to the right and below this table.

Suggestions??

Thanks in advance

This is my current code. It does nothing when I click the command button
People List is the A column (names)
txtRows is a textbox at the bottom of the page which says the row number the person is in the list


Code:
Private Sub cmdDeleteEntry_Click()
With Range("People_Table")
     .Range("People_List")(txtRow.Value).EntireRow.Delete shift: x1shiftup
     .Rows(.Rows.Count + 1).EntireRow.Insert
     .Resize(.Rows.Count +1, .Columns.Count).People_Table
end with

end sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
basically is there any way to limit the delete or insert row to a certain number of columns and make it dynamic so it deletes/inserts a new row for only the current record that your viewing in the userform (txtrow in this case)

Any suggestions are very much appreciated. I'm totally new to vba, but hoping to find a solution. Is this a very unique issue?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,978
Latest member
rrauni

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