Passing arguments with worksheet_change to dynamically update ranges

Prevost

Board Regular
Joined
Jan 23, 2014
Messages
198
Hi There. I have found a sub that will dynamically update named ranges in worksheets. There are two things that I would like to know if possible. First, I would like to know if there is a way to disregard blank cells in that range (starting at A3 that goes to the last row). I am using that range for a combobox and would prefer it if there were not any blank selections in the list. Second, I have multiple ranges and I do not want to call this sub everytime, so is there a way to create this macro with variables to insert? I am still not 100% clear on passing arguments and am trying to learn more. I thought something like

Private Sub worksheet_change(ByVal target as Range, Column as String, FirstCell as String, RangeName as String)

and then filling in the values for Column, the starting cell and the name of the range....

Thanks!
Code:
Private Sub worksheet_change(ByVal target As Range)
If Intersect(target, Columns("A:A")) Is Nothing Then Exit Sub
Dim lRow As Integer
lRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A3:A" & lRow).Name = "MyRange"
End Sub
 
That's right you can't pass your own arguments to any of the built-in events.

If you try you'll get a compile error, the text of which escapes me right now.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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