PDA

View Full Version : Solved: Ampersand function help



alok2007
05-23-2007, 09:59 PM
Suppose cell A1 contains MAY,A2 contains 2007, and cell A3 contains INR 20,000. Cell A4 contains formula
="Amount due for the month of"&" "&A1&" "&A2&"is INR "&A3&" only"
Result is: Amount due for the month of May 2007is INR 20000 only
Want to make May 2007 20000 as BOLD in the Result. HOw this can be done?

Bob Phillips
05-24-2007, 12:13 AM
Only with VBA.

alok2007
05-24-2007, 12:44 AM
Code plz,if possible!!!!!!!!!!

Bob Phillips
05-24-2007, 01:33 AM
With ActiveCell
.Value = Cells(.Row, "A").Text & " " & _
Cells(.Row, "B").Text & " " & _
Cells(.Row, "C").Text
.Characters(1, Len(Cells(.Row, "A").Text) + _
Len(Cells(.Row, "B").Text) + 1).Font.Bold = True
End With

alok2007
05-24-2007, 02:28 AM
Thanks for the code. But where to put it?

Bob Phillips
05-24-2007, 02:58 AM
That depends upon what it is that you want to trigger the code.

alok2007
05-24-2007, 09:44 PM
I dont have very depth knowledge of codes.Only I can use the code in excel & as such my knowledge is very limited. I copied and pasted the code in sheet modules,This workbook module,& standard module in VBE of excel. When I return to excel & press Alt F8, no macro is showing in any case and as such I cant run the same . Plz elaborate as to how can i trigger the code.

mdmackillop
05-26-2007, 02:29 AM
See attached sample
Sheet 1 is triggered by button and will add data to the active cell.
Sheet 2 is triggered when data is changed in column 3

Basic code is
Option Explicit
Sub Joins()
Dim str As String, i As Long, j As Long
With ActiveCell
str = "Amount due for month of " & Cells(.Row, "A").Text & " " _
& Cells(.Row, "B").Text & " is " & Cells(.Row, "C").Text & " only."
.Value = str
i = Len(Split(str)(5)) 'Get length of Month
j = Len(Split(str)(9)) 'Get length of Amount
.Characters(25, i + 5).Font.Bold = True 'Embolden Month & Year
.Characters(38 + i, j).Font.Bold = True 'Embolden Amount
End With
End Sub

Bob Phillips
05-26-2007, 10:02 AM
I dont have very depth knowledge of codes.Only I can use the code in excel & as such my knowledge is very limited. I copied and pasted the code in sheet modules,This workbook module,& standard module in VBE of excel. When I return to excel & press Alt F8, no macro is showing in any case and as such I cant run the same . Plz elaborate as to how can i trigger the code.

As I said, there are many ways. You need to tell us how you want it to be invoked.

Cyberdude
05-26-2007, 03:12 PM
Hi, alok! Here's a little nit picking, for what it's worth.

The ampersand (&) is not a function. Technically it is an operator. Specifically is is a text operator. It's purpose is to join the value that precedes it to the value that follows it. But then you obviously know that. A function is a VBA procedure (macro) or an Excel formula which, when executed, returns a value to the caller. You can create an Excel function by writing a formula, then assigning a so-called defined name to it. Thereafter you can refer to the defined name instead of writing the whole formula.

Just a little educational material to lighten the day.
Sid

alok2007
05-27-2007, 09:37 PM
Many thanks for the clarication. Code is fully working. thanks to all for the support.