Target Range Wanted

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,953
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I need to get the Range object Target that is sent to the Worksheet Selection change event - from somewhere else.
If it's possible what needs to be known / done?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If you're using it somewhere else, why can't you just use Selection in your code??

Otherwise, please provide more details about what you are trying to accomplish
 
Upvote 0
Because it changes. I have a function that uses target for various things. I could multi-purpose use it if I can create another 'target'.
 
Upvote 0
Target is related to event code.
While you could assign this range to a public variable. It would change every time it is used. More info would be helpful

Target would change everytime you changed the selection in the Selection Change event.

I still don't understand why you can't use Selection and determine if that's in the range you want, just like you can do with Target.

For example, if you had some cells selected in Column A. This code would only color the background of the cells Red, while excluding anything selected outside of Column A.
VBA Code:
Sub test()
Dim c As Range, d As Range
Set d = Intersect(Selection, Range("A:A"))
If d Is Nothing Then Exit Sub
For Each c In d
    c.Interior.Color = vbRed
Next
End Sub

or you could pass the Target range to another function or macro but without more details about what you are doing, I don't know how I can help further.
 
Upvote 0
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call test(Target)
End Sub


Sub test(r As Range)
r.Interior.Color = vbRed
End Sub

This isn't very useful because it will color every cell you select red, but it shows how you could pass the value to another sub or function
 
Upvote 0
I'll try and explain it a bit better... LOL but may just complicate it further.
In the worksheet SelectionChange I show details from target into the status bar.
Then in the d-click event I send Target into a Function. This populates another worksheet that becomes the row source for a listbox.
If the user selects a different entry the listbox, I want to show those (new) details in the status bar, replacing what was there
With Target for that new selection I can reuse the same function to populate the status bar.
 
Upvote 0
Target is just a Range variable. How does the entry in the listbox translate to a range?
 
Upvote 0

Forum statistics

Threads
1,221,490
Messages
6,160,133
Members
451,622
Latest member
xmrwnx89

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