how to make macro to combine text from 2 cells?

G

Guest

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!
 
T

Tom Ogilvy

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
 
C

Corey

OR try:


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

End Sub



Corey....
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top