Good evening all
I'm relatively new to the world of VBA so please forgive me if I make any mistakes here. I've had a go at this already (I can insert and delete a row, but no other logic to specify where to insert the row, how to format it etc...), but the more intricate parts are where it all falls down so any help is much appreciated.
In short I am trying to make two macros (which I will attach to buttons for a user to click). One button inserts a row inside an existing Range, the second button deletes a row inside an existing range. However, there are additional complexities beyond this.
Structure of the range.
At any one time, my data range will be at least 4 rows long. This includes a header row, a footer row and two rows for data. The range should be able to grow (additional data rows) but there should always be a header at the top and a footer at the bottom.
Macro 1 - Insert
I'd like to be able to insert a row at the bottom of my range, just above the footer row. So, in the example of four existing rows (Header, Data1, Data2, Footer) I would like this row to always go just before the footer (Header, Data1, Data2, NEW ROW, footer).
I would also like the macro to then copy the formatting (format paint) from the entirety of data1, then paste this formatting over all data rows, including the row the formatting was copied from. So in the example of (Header, data1, data2, NEW ROW, footer) I would like the VBA to copy formatting from the data1 row, and paste it all over data1, data2 and NEW ROW.
This entire thing should be endlessely repeatable, one row at a time.
Macro 2 - Delete
I'd like to have a button that would delete the entire row directly above footer. So in the example (Header, Data1, Data2, NEW ROW, footer) it would entirely delete NEW ROW. However, if the total range is just four rows, the deletion should not operate at all. I.e. the range can never be less than four rows (header, data1, data2, footer).
For this example by worksheet is called Test_Sheet and the range is named Test_Range.
This is making my head spin. I'm assuming I need the VBA to constantly count how many rows are currently in the range and adjust things accordingly, but that's easier said than done.
I'm relatively new to the world of VBA so please forgive me if I make any mistakes here. I've had a go at this already (I can insert and delete a row, but no other logic to specify where to insert the row, how to format it etc...), but the more intricate parts are where it all falls down so any help is much appreciated.
In short I am trying to make two macros (which I will attach to buttons for a user to click). One button inserts a row inside an existing Range, the second button deletes a row inside an existing range. However, there are additional complexities beyond this.
Structure of the range.
At any one time, my data range will be at least 4 rows long. This includes a header row, a footer row and two rows for data. The range should be able to grow (additional data rows) but there should always be a header at the top and a footer at the bottom.
Macro 1 - Insert
I'd like to be able to insert a row at the bottom of my range, just above the footer row. So, in the example of four existing rows (Header, Data1, Data2, Footer) I would like this row to always go just before the footer (Header, Data1, Data2, NEW ROW, footer).
I would also like the macro to then copy the formatting (format paint) from the entirety of data1, then paste this formatting over all data rows, including the row the formatting was copied from. So in the example of (Header, data1, data2, NEW ROW, footer) I would like the VBA to copy formatting from the data1 row, and paste it all over data1, data2 and NEW ROW.
This entire thing should be endlessely repeatable, one row at a time.
Macro 2 - Delete
I'd like to have a button that would delete the entire row directly above footer. So in the example (Header, Data1, Data2, NEW ROW, footer) it would entirely delete NEW ROW. However, if the total range is just four rows, the deletion should not operate at all. I.e. the range can never be less than four rows (header, data1, data2, footer).
For this example by worksheet is called Test_Sheet and the range is named Test_Range.
This is making my head spin. I'm assuming I need the VBA to constantly count how many rows are currently in the range and adjust things accordingly, but that's easier said than done.
Book1 | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | ||||||||
2 | Title 1 | Title 2 | Title 3 | Title 4 | Title 5 | |||
3 | 04-May-20 | Test 1 | Test 1 | Test 1 | Test 1 | |||
4 | 04-May-20 | Test 1 | Test 1 | Test 1 | Test 1 | |||
5 | ||||||||
6 | ||||||||
Test_Sheet |