Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Macro to concatenate or merge cells

A loop like this would work

Sub test()
Range("A1").Select
For Z = 1 To 10 '(set your start and end row as needed)
If Cells(Z, 1) = "X" Then
Range("E2").FormulaR1C1 = Range("E2").FormulaR1C1 & "&R" & CStr(Z) &"C4"
End If
Next Z
Range("E2").FormulaR1C1 = "=" & Right(Range("E2").FormulaR1C1,
Len(Range("E2").FormulaR1C1) - 1) 'This needs to be one line
'This removes the initial & from the formula and adds the =
End Sub


--
If this helps, please remember to click yes.


"Kell2604" wrote:

Awesome Paul - that solves half of my problem. The other part is that the
macro needs to keep going back to the same cell to add the additional data.
For example, I might have 6 total rows that all have X in column A. It is
the values for column D that I want to merge into one cell for all 6 rows.
So lets say my concatenating is happening in cell E2 the macro needs to keep
going back to E2 to add the new cells worth of data. Should I do some sort
of find and paste. Like telling it to look for the empty cell and then
offset up 1 (assuming the cells beneath my formula are empty - because I'm
not pasting anything in them).

"Paul C" wrote:

Yes VBA can. Use a format like this.

Range("B3").Formula = Range("B3").Formula + "&F5"

If the original formula in B3 was C5&D5, this will change the formula to
C5&D5&F5

Just be careful that the added statment will still constitute a valid
formula. Adding "&F5&" for example would give an error

--
If this helps, please remember to click yes.


"Kell2604" wrote:

Hi -

I am working on a macro that I need to concatenate multiple cells (I'm using
the =A1&"_"&B1 formula). My problem is that the range of cells I need to
merge is variable based on the data in a previous column. If cell A30 = X
then add cell D30 to a concantenated list that has already been started;
next if A31 = X then add cell D31 to the afore mentioned list, etc. etc. I
can get the macro to evaluate the criteria but can it add a cell (D30) to a
cell which already has an existing concatenated formula? ie. (=L2&" "&L3&"
"&L4&" "&L5 + a new cell)

Hope your not too confused. Thanks in advance for your help!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MERGE ROW CELLS BY MACRO K[_2_] Excel Programming 2 February 16th 08 09:44 AM
Macro to concatenate previously selected cells Grumpy Excel Programming 1 November 22nd 05 02:42 PM
Macro Help: Concatenate Populated Cells in Column A TJM Excel Discussion (Misc queries) 3 June 11th 05 11:25 AM
Concatenate and Mail Merge Tara Excel Worksheet Functions 1 June 10th 05 06:08 PM
Merge cells using macro Tom Ogilvy Excel Programming 0 August 7th 03 07:20 PM


All times are GMT +1. The time now is 02:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"