Concatenation 2 Texts

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Suppose I have two Texts: "Text1" in A1 and "Text2" in C1. I want to make a
concatenation of A1 and C1 in cell C3, and make the font of "Text1" bold, but
not "Text2". Is there a way to do this in Excel?
 
You would need VBA.

With ActiveCell
.Value = Range("A1").Value & Range("C1").Value
.Characters(Len(Range("A1").Value) + 1, _
Len(Range("C1").Value)).Font.Bold = True
End With


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Tanks a lot, Bob. It works, but... I need "Text1" to be bold not "Text2" and
I need to seperate between "text1" and "Text2" e.g. by the sign: "-". I'll be
very thankful if you can help.
 
No problem

With ActiveCell
.Value = Range("A1").Value & "-" & Range("C1").Value
.Characters(1, Len(Range("A1").Value) ) _
.Font.Bold = True
End With


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Once again, thank you very much for your help and your fast response Bob. I
tried it and it works... But I still need some help. I need the concatenation
to be in a fixed cell (e.g. D12), instead of the active cell... I tried the
following code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Range("D12")
.Value = Range("A1").Value & "-" & Range("C1").Value
.Characters(1, Len(Range("A1").Value)) _
.Font.Bold = True
End With

It works at first, but once I click on any cell, all the text in D12 becomes
bold. Can you do something to make it work properly... It will be great if
you can help. If you can't, it's o.k. and I'm very thankful to you for trying
helping me before.
 
Best to clear it first

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Range("D12")
.Font.Bold = False
.Value = Range("A1").Value & "-" & Range("C1").Value
.Characters(1, Len(Range("A1").Value)) _
.Font.Bold = True
End With
End Sub

A small problem here is that it fires every time you select a cell, any c
ell. It would be better to be targeted at one particular cell. When do you
want the setup and formatting to happen?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Hi Bob...

Here is what I am trying to do exactly:

I have a text in cell A1, and another text in cell C1. I need to concatenate
them in cell D12. The font of the text from A1 should be normal, while the
text from cell C1 should be bold. I need to seperate between the two texts by
the sign " - ". I need this formatting to happen after I enter or modify the
text in cell A1 and cell C1.

I tried the code you have provided me with in your last post (the modified
one). Unlike before, it seems to work fine now. When I click on a cell now,
cell D12 formatting remains the same (i.e. Text from A1 normal, and Text from
C1 bold). That's basically what I need...

Thank you SO MUCH for your great help Bob. (^_^)
 
This should also work, and is better as it fires ONLY when A1 or C1 is
changed

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1,C1"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Range("D12")
.Font.Bold = False
.Value = Range("A1").Value & "-" & Range("C1").Value
.Characters(1, Len(Range("A1").Value)) _
.Font.Bold = True
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

Just remove your code and replace with that, the whole procedure.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Hi Bob...

I've just tried the code, and It's working perfectly. Many, many thanks
indeed. Thanks to you Bob, my problem is now solved. (^_^)
 
Back
Top