Get cell values from the selected cells by columns or by ranges:

carmelai

New Member
Joined
Nov 11, 2022
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
I have this Excel sheet structure with a VBA in the sheet module. It looks like this:

0000X VBA CODE.xlsm
ABCDEFG
1ARTICLEADJECTIVENOUNVERBPREPOSITIONARTICLENOUN
2ARTICLEARTICLEARTICLEARTICLEARTICLEARTICLEARTICLE
3
4THEREDTREEFALLSONTHECAR
5ABIGTOYBURNSWITHAACTOR
6ANEXOTICHOUSEWALKSLIKEANFLAME
Foaie1


The VBA looks like this:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Range("A2").Value = ActiveCell.Value

Range("B2").Value = ActiveCell.Value

Range("C2").Value = ActiveCell.Value

Range("D2").Value = ActiveCell.Value

Range("E2").Value = ActiveCell.Value

Range("F2").Value = ActiveCell.Value

Range("G2").Value = ActiveCell.Value

End Sub

In cell A2 I want to get the value of any of the active selected cells from range A4:A6 or from column A. Then when I select a cell from range B4:B6 or column B I want to get a new value in cell B2 but to keep the previous value unchanged in cell A2. And so on with all the columns to the right till I get a complete sentence. I need this as my sheet will have thousands of rows for each main part of speech so I will scroll and as I scroll I will select new words to create new sentences.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Intersect(Target.EntireColumn, Rows(2)).Value = Target.Value
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Intersect(Target.EntireColumn, Rows(2)).Value = Target.Value
End Sub
Thank you very much! It works like a charm.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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