Enhancing current VB code

rfinnegan

Board Regular
Joined
Mar 15, 2005
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hi All:

Last year someone was kind enough to provide the following code which allows me to click on any name in any cell, and have that name appear in a certain cell (D22).

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target(1).Address <> "$d$22" Then Range("d22").Value = "" & Target(1).Formula
End Sub

I'd like to take this a step further, and select one of 3 cells in column 'I' and have the data in the correcponding cells J and K populate cells e3 and g3.

For example, I click on cell i4, and the data in cells j4 and k4 magically appear in e3 and g3. If I selected cell i5, the data in cells j5 and k5 appear in e3 and g3. Or, if I seleted i3, j3 and k3 would populate e3 and g3.

Thanks in adavance.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this. Not sure if you want the 'Else' part but you can just remove that if you don't want it.

<font face=Courier New><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_SelectionChange(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(ActiveCell, Range("I3:I5")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        Range("E3").Value = ActiveCell.Offset(, 1).Value<br>        Range("G3").Value = ActiveCell.Offset(, 2).Value<br>    <SPAN style="color:#00007F">Else</SPAN><br>        Range("E3,G3").ClearContents<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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