Although, as MasterMix says, this is most easily achieved using a formula, if you have a reason to use VBA, it depends on how you want to specify the cells.
You can do this as a function:
Private Function addTwoCells (rngA As Range, rngB As Range) As String
addTwoCells = rngA & rngB
End function All this makes replication (much faster) the built-in Excel concatenation function.
You can also make this one of about a hundred ways in the procedure, here one of the methods will tell the user ranges:
Private Sub addTwoCellsProc ()
Dim rnga as string
Dim rngb as string
Dim rngoutput as string
Dim rngtest as range
Do
rngA = InputBox ("Please enter first cell address", "Cell A")
rngA = Range (rngA) .Cells (1, 1) .Address
Set rngTest = Intersect (Range (rngA) .Cells (1, 1), ActiveSheet.Cells)
Loop Until Not rngTest Is Nothing
Do
rngB = InputBox ("Please enter second cell address", "Cell B")
rngB = Range (rngB) .Cells (1, 1) .Address
Set rngTest = Intersect (Range (rngB), ActiveSheet.Cells)
Loop Until Not rngTest Is Nothing
Do
rngOutput = InputBox ("Please enter destination cell address", "Output cell")
Set rngTest = Intersect (Range (rngOutput), ActiveSheet.Cells)
Loop Until Not rngTest Is Nothing
Range (rngOutput) = Range (rngA) & Range (rngB)
End sub You can also use predefined ranges and scroll through them if you have multiple ranges to combine. If you explain a little more about the script, then someone can provide more specific code.
Lunatik
source share