Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KK KK is offline
external usenet poster
 
Posts: 61
Default how to make macro to combine text from 2 cells?

I tried recording macro and it does not work with relative addressing.

A1 abc A2 xyz

I want A3 to be abcxyz

If you run above recorded macro for cells B1 B2 and B3 I get copy of A1 A2 A3
not the real content of B1 and B2

Thanks for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to make macro to combine text from 2 cells?

Assume B1 is the ActiveCell when you run the macro

Sub Macro1()
ActiveCell.offset(2,0).Value = ActiveCell.Value &
ActiveCell.offset(1,0).Value
End Sub


If B3 is the activeCell when you run the macro

Sub Macro1()
if ActiveCell.Row = 3 then
ActiveCell = ActiveCell.Offset(-2,0).Value & ActiveCell.offset(-1,0).Value
End if
End Sub


--
Regards,
Tom Ogilvy


"kk" wrote in message
...
I tried recording macro and it does not work with relative addressing.

A1 abc A2 xyz

I want A3 to be abcxyz

If you run above recorded macro for cells B1 B2 and B3 I get copy of A1 A2
A3
not the real content of B1 and B2

Thanks for your help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default how to make macro to combine text from 2 cells?

OR try:


Sub Button1_Click()
With Sheet1
Range("A3").Value = Range("A1").Value & Range("A2").Value
End With

End Sub



Corey....
"kk" wrote in message
...
I tried recording macro and it does not work with relative addressing.

A1 abc A2 xyz

I want A3 to be abcxyz

If you run above recorded macro for cells B1 B2 and B3 I get copy of A1 A2
A3
not the real content of B1 and B2

Thanks for your help!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default how to make macro to combine text from 2 cells?

Sub splice_um()
Set r = Selection
r.Offset(2, 0).Value = r.Value & r.Offset(1, 0).Value
End Sub


Select anywhere on the first row and the third row will contain the
concatenation of the first two rows for that column.

For example Select Z1 and Z3 will get filled.
--
Gary's Student


"kk" wrote:

I tried recording macro and it does not work with relative addressing.

A1 abc A2 xyz

I want A3 to be abcxyz

If you run above recorded macro for cells B1 B2 and B3 I get copy of A1 A2 A3
not the real content of B1 and B2

Thanks 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
Combine Text Cells lightbulb Excel Discussion (Misc queries) 3 July 24th 08 02:40 PM
Combine text and cells Jen Excel Discussion (Misc queries) 2 May 21st 07 08:48 PM
How can I combine text from several cells into one? Michael Excel Discussion (Misc queries) 5 January 16th 07 10:25 PM
Macro to Combine 2 columns to make one column without merging JRM Excel Discussion (Misc queries) 1 December 31st 05 08:27 PM
combine worksheet functions to make macro to automate everything mike Excel Programming 4 December 21st 05 05:13 PM


All times are GMT +1. The time now is 09:08 PM.

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

About Us

"It's about Microsoft Excel"