Worksheet_SelectionChange(ByVal Target As Range) for Newbie

cliffmid

New Member
Joined
Aug 5, 2016
Messages
8
I have never used "Target" before. I have a list of name (a18:a150) and want to click on one and have the name inserted into textBox1 in userForm2. I can get the range set correctly and "userform2.show" brings up userform2 (which has my textbox1). I cannot figure out how to get the name from a18:a150 to be inserted into textbox1. I am very new to VBA. Most of what I have gleaned has come from videos and "reverse engineering" similar code for my project. Can you help me?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi & welcome to MrExcel.
How about
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Intersect(Target, Range("A18:A150")) Is Nothing Then Exit Sub
   UserForm2.TextBox1.Value = Target
   UserForm2.Show
End Sub
 
Upvote 0
Wish I could delete this thread. My question makes the problem too complex for my VBA skills. I think the easiest solution to what I want to do is be able to click on a cell in a10:a150 and have the contents of that selected cell appear in cell d10. I think if I could do that I would understand "Val Target as Range" better, and I could use that to use "userForm2.show". From there, I would be able to get my project finished.
 
Upvote 0
Have you tried the code I posted?
 
Upvote 0
You got it. I "reverse engineered" what you sent to become:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Intersect(Target, Range("A18:A150")) Is Nothing Then Exit Sub
Sheet1.Range("d10").Value = Target
UserForm2.Show
End Sub

It does precisely what I needed to do. Thank you so much.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
You're welcome & thanks for the feedback

I did and showed my "reverse engineering." It worked beautifully. I am bothered you did not get my note. That would not be polite on my part. When someone takes time out of his day to help, you don't use the code and ignore the person who helped you. I am sorry my note did not get to you.

BTW. THANK YOU again. You solved a perplexment for me and I really appreciate it.

Cliiff
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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