Concatenation 2 Texts

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?
 
B

Bob Phillips

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)
 
G

Guest

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.
 
B

Bob Phillips

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)
 
G

Guest

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.
 
B

Bob Phillips

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)
 
G

Guest

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. (^_^)
 
B

Bob Phillips

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)
 
G

Guest

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. (^_^)
 

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

Similar Threads


Top