![]() |
Macro to concatenate previously selected cells
Hello, everyone!
I'm trying to write a macro that would allow me to concatenate the contents of several already selected (but not adjacent) cells into one cell. In other words, I want to be able to go to a worksheet, select several different cells by using the Ctrl key and then run the macro to concatenate what is in those cells into one cell, preferably the upper leftmost cell of the ones selected. Any help on this would be greatly appreciate. My first post, so don't chastise me too much if what I'm asking has a simple solution. Thanks, |
Macro to concatenate previously selected cells
How about:
Sub Macro1() Dim r As Range Dim rr As Range Dim i As Integer Dim t As String i = 0 t = "" For Each r In Selection If i = 0 Then i = 1 Set rr = r End If t = t & r.Value Next rr.Value = t End Sub I only tried it once. -- Gary's Student "Grumpy" wrote: Hello, everyone! I'm trying to write a macro that would allow me to concatenate the contents of several already selected (but not adjacent) cells into one cell. In other words, I want to be able to go to a worksheet, select several different cells by using the Ctrl key and then run the macro to concatenate what is in those cells into one cell, preferably the upper leftmost cell of the ones selected. Any help on this would be greatly appreciate. My first post, so don't chastise me too much if what I'm asking has a simple solution. Thanks, |
All times are GMT +1. The time now is 10:36 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com