apply macro to last row in a table

redink20

New Member
Joined
Jun 9, 2015
Messages
2
I have a macro that runs based on a row and column range, for example the macro occurs if someone selects a cell in column 5-8 and row 3-48. However, these cells are in a table called "Tbl_Results" and as users may want to extend the number of rows in the table, so I would like this macro to extend as well. With the current code, even by added a row in the table, the macro stops at row 48. How would I indicate the number of rows to encompass all rows in "Tbl_Results"? I don't believe the column numbers will be changing.

Currently, it is written as:
If Target.Column >= 5 And Target.Column <= 8 And Target.Row >= 3 And Target.Row <= 48

Thank you.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I figured it out - I changed the code of line to read:
If Target.Row >= 3 And Target.Column >= 5 And Target.Column <= 8 And Target.Row <= Range("A1").CurrentRegion.Rows.Count
 
Upvote 0

Forum statistics

Threads
1,217,019
Messages
6,134,056
Members
449,857
Latest member
caracal

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