PC Review


Reply
Thread Tools Rate Thread

Complex Formatting of cell

 
 
=?Utf-8?B?S2FyYW4=?=
Guest
Posts: n/a
 
      3rd Aug 2007
Using the format cell dialog box one can choose Custom Format and give the
format as

"String" ###0.0

The end result is a cell which has a number and text (String) in it, but
when you click on the contents of the cell you can only see the number and
cannot see the text (as it is in the format)

However I don't want to to do this manually for each cell as the string
changes for each cell.

I'm trying to figure out how a macro could set a custom format of a cell to
something like "String from RC[-5]" ###0.0

Using something like
X = "String from RC[-5] " & " ###0.0"
Y = "=RC[-11]"
ActiveCell = format(Y, X)

ends up showing both the string and the number in the cell, instead of
having the string in the format and not in the cell.

How can one put define a custom number format with a variable "String" in
the format?
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Aug 2007
X = "String from RC[-5] " & " ###0.0"
Y = "=RC[-11]"
ActiveCell.Formula = Y
Activecell.NumberFormat = X

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Karan" <(E-Mail Removed)> wrote in message
news:C1F77F2C-3263-4367-A285-(E-Mail Removed)...
> Using the format cell dialog box one can choose Custom Format and give the
> format as
>
> "String" ###0.0
>
> The end result is a cell which has a number and text (String) in it, but
> when you click on the contents of the cell you can only see the number and
> cannot see the text (as it is in the format)
>
> However I don't want to to do this manually for each cell as the string
> changes for each cell.
>
> I'm trying to figure out how a macro could set a custom format of a cell
> to
> something like "String from RC[-5]" ###0.0
>
> Using something like
> X = "String from RC[-5] " & " ###0.0"
> Y = "=RC[-11]"
> ActiveCell = format(Y, X)
>
> ends up showing both the string and the number in the cell, instead of
> having the string in the format and not in the cell.
>
> How can one put define a custom number format with a variable "String" in
> the format?



 
Reply With Quote
 
=?Utf-8?B?RHVrZSBDYXJleQ==?=
Guest
Posts: n/a
 
      3rd Aug 2007
from the Help file

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"



"Karan" wrote:

> Using the format cell dialog box one can choose Custom Format and give the
> format as
>
> "String" ###0.0
>
> The end result is a cell which has a number and text (String) in it, but
> when you click on the contents of the cell you can only see the number and
> cannot see the text (as it is in the format)
>
> However I don't want to to do this manually for each cell as the string
> changes for each cell.
>
> I'm trying to figure out how a macro could set a custom format of a cell to
> something like "String from RC[-5]" ###0.0
>
> Using something like
> X = "String from RC[-5] " & " ###0.0"
> Y = "=RC[-11]"
> ActiveCell = format(Y, X)
>
> ends up showing both the string and the number in the cell, instead of
> having the string in the format and not in the cell.
>
> How can one put define a custom number format with a variable "String" in
> the format?

 
Reply With Quote
 
=?Utf-8?B?S2FyYW4=?=
Guest
Posts: n/a
 
      7th Aug 2007
Hi Bob...thanks for this. However there is still one problem because of which
this doesnot work.
The value of X here turns out to be "String ###0.0"....and this is not a
valid format. It has to be ""String" ###0.0"
I tried using Chr(34) instead of a " but that isn't working. This is what I
did:

X = "Chr(34) String Chr(34)" & " ###0.0"
Y = "=RC[-11]"
ActiveCell.Formula = Y
Activecell.NumberFormat = X

Any idea how I could pass an " in the Number format?

"Bob Phillips" wrote:

> X = "String from RC[-5] " & " ###0.0"
> Y = "=RC[-11]"
> ActiveCell.Formula = Y
> Activecell.NumberFormat = X
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Karan" <(E-Mail Removed)> wrote in message
> news:C1F77F2C-3263-4367-A285-(E-Mail Removed)...
> > Using the format cell dialog box one can choose Custom Format and give the
> > format as
> >
> > "String" ###0.0
> >
> > The end result is a cell which has a number and text (String) in it, but
> > when you click on the contents of the cell you can only see the number and
> > cannot see the text (as it is in the format)
> >
> > However I don't want to to do this manually for each cell as the string
> > changes for each cell.
> >
> > I'm trying to figure out how a macro could set a custom format of a cell
> > to
> > something like "String from RC[-5]" ###0.0
> >
> > Using something like
> > X = "String from RC[-5] " & " ###0.0"
> > Y = "=RC[-11]"
> > ActiveCell = format(Y, X)
> >
> > ends up showing both the string and the number in the cell, instead of
> > having the string in the format and not in the cell.
> >
> > How can one put define a custom number format with a variable "String" in
> > the format?

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      11th Aug 2007
Does this do it

X = """String from RC[-5] """ & " ###0.0"
Y = "=RC[-11]"
ActiveCell.Formula = Y
ActiveCell.NumberFormat = X


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Karan" <(E-Mail Removed)> wrote in message
news:C9C2B28A-8067-453B-80AA-(E-Mail Removed)...
> Hi Bob...thanks for this. However there is still one problem because of
> which
> this doesnot work.
> The value of X here turns out to be "String ###0.0"....and this is not a
> valid format. It has to be ""String" ###0.0"
> I tried using Chr(34) instead of a " but that isn't working. This is what
> I
> did:
>
> X = "Chr(34) String Chr(34)" & " ###0.0"
> Y = "=RC[-11]"
> ActiveCell.Formula = Y
> Activecell.NumberFormat = X
>
> Any idea how I could pass an " in the Number format?
>
> "Bob Phillips" wrote:
>
>> X = "String from RC[-5] " & " ###0.0"
>> Y = "=RC[-11]"
>> ActiveCell.Formula = Y
>> Activecell.NumberFormat = X
>>
>> --
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>> "Karan" <(E-Mail Removed)> wrote in message
>> news:C1F77F2C-3263-4367-A285-(E-Mail Removed)...
>> > Using the format cell dialog box one can choose Custom Format and give
>> > the
>> > format as
>> >
>> > "String" ###0.0
>> >
>> > The end result is a cell which has a number and text (String) in it,
>> > but
>> > when you click on the contents of the cell you can only see the number
>> > and
>> > cannot see the text (as it is in the format)
>> >
>> > However I don't want to to do this manually for each cell as the string
>> > changes for each cell.
>> >
>> > I'm trying to figure out how a macro could set a custom format of a
>> > cell
>> > to
>> > something like "String from RC[-5]" ###0.0
>> >
>> > Using something like
>> > X = "String from RC[-5] " & " ###0.0"
>> > Y = "=RC[-11]"
>> > ActiveCell = format(Y, X)
>> >
>> > ends up showing both the string and the number in the cell, instead of
>> > having the string in the format and not in the cell.
>> >
>> > How can one put define a custom number format with a variable "String"
>> > in
>> > the format?

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?S2FyYW4=?=
Guest
Posts: n/a
 
      13th Aug 2007
Nopes, it doesn't.
"""String from RC[-5] """ is the same as trying to pass 3 strings.
The first one would be "", the second "String from RC[-5] " and the third
would be "" again.
I'm at my wits end!

Any further ideas?
Cheers, Karan


"Bob Phillips" wrote:

> Does this do it
>
> X = """String from RC[-5] """ & " ###0.0"
> Y = "=RC[-11]"
> ActiveCell.Formula = Y
> ActiveCell.NumberFormat = X
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Karan" <(E-Mail Removed)> wrote in message
> news:C9C2B28A-8067-453B-80AA-(E-Mail Removed)...
> > Hi Bob...thanks for this. However there is still one problem because of
> > which
> > this doesnot work.
> > The value of X here turns out to be "String ###0.0"....and this is not a
> > valid format. It has to be ""String" ###0.0"
> > I tried using Chr(34) instead of a " but that isn't working. This is what
> > I
> > did:
> >
> > X = "Chr(34) String Chr(34)" & " ###0.0"
> > Y = "=RC[-11]"
> > ActiveCell.Formula = Y
> > Activecell.NumberFormat = X
> >
> > Any idea how I could pass an " in the Number format?
> >
> > "Bob Phillips" wrote:
> >
> >> X = "String from RC[-5] " & " ###0.0"
> >> Y = "=RC[-11]"
> >> ActiveCell.Formula = Y
> >> Activecell.NumberFormat = X
> >>
> >> --
> >> HTH
> >>
> >> Bob
> >>
> >> (there's no email, no snail mail, but somewhere should be gmail in my
> >> addy)
> >>
> >> "Karan" <(E-Mail Removed)> wrote in message
> >> news:C1F77F2C-3263-4367-A285-(E-Mail Removed)...
> >> > Using the format cell dialog box one can choose Custom Format and give
> >> > the
> >> > format as
> >> >
> >> > "String" ###0.0
> >> >
> >> > The end result is a cell which has a number and text (String) in it,
> >> > but
> >> > when you click on the contents of the cell you can only see the number
> >> > and
> >> > cannot see the text (as it is in the format)
> >> >
> >> > However I don't want to to do this manually for each cell as the string
> >> > changes for each cell.
> >> >
> >> > I'm trying to figure out how a macro could set a custom format of a
> >> > cell
> >> > to
> >> > something like "String from RC[-5]" ###0.0
> >> >
> >> > Using something like
> >> > X = "String from RC[-5] " & " ###0.0"
> >> > Y = "=RC[-11]"
> >> > ActiveCell = format(Y, X)
> >> >
> >> > ends up showing both the string and the number in the cell, instead of
> >> > having the string in the format and not in the cell.
> >> >
> >> > How can one put define a custom number format with a variable "String"
> >> > in
> >> > the format?
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?S2FyYW4=?=
Guest
Posts: n/a
 
      13th Aug 2007
Duke,
Thanks for the help. But this is not what I'm looking for.
I'm looking for a Macro that does the same as the following windows process:
Click on a cell and click on "Format cells", then on custom format category.
In the type the custom format is "String" ###0.0.

What I'm trying to achieve is that the "String" should be a variable. The
end result of such a format is a cell which displays a number along with a
string. However if you click on the cell, it only has a number as a value.
Hence you can add/ subtract such cells even though it has a number and a
string.

For example the string could be something like "Kisses". In such a cell if
you put a number 10, then it will show up as "10 Kisses" in the cell. You can
format many cells and then add all cells to get a sum of all kisses

Cheers, Karan


"Duke Carey" wrote:

> from the Help file
>
> Worksheets("Sheet1").Range("A17").NumberFormat = "General"
> Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
> Worksheets("Sheet1").Columns("C"). _
> NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
>
>
>
> "Karan" wrote:
>
> > Using the format cell dialog box one can choose Custom Format and give the
> > format as
> >
> > "String" ###0.0
> >
> > The end result is a cell which has a number and text (String) in it, but
> > when you click on the contents of the cell you can only see the number and
> > cannot see the text (as it is in the format)
> >
> > However I don't want to to do this manually for each cell as the string
> > changes for each cell.
> >
> > I'm trying to figure out how a macro could set a custom format of a cell to
> > something like "String from RC[-5]" ###0.0
> >
> > Using something like
> > X = "String from RC[-5] " & " ###0.0"
> > Y = "=RC[-11]"
> > ActiveCell = format(Y, X)
> >
> > ends up showing both the string and the number in the cell, instead of
> > having the string in the format and not in the cell.
> >
> > How can one put define a custom number format with a variable "String" in
> > the format?

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      13th Aug 2007
Hi Karen,

Not really sure what you are trying to do or rather what the problem is.
Does the following help -

Sub test()

[a2] = "Kisses"
[b2] = 12.345678

Set rng = Range("C2")
For Each cell In rng
s = Chr(34) & cell.Offset(, -2) & Chr(34) & " 0.000"
cell.NumberFormat = s
cell.Value = cell.Offset(, -1)
cell.Formula = "=RC[-1]"
Next

rng.Columns.AutoFit

Debug.Print Range("C2").Value ' 12.345678
Debug.Print Range("C2").Text ' Kisses 12.346

End Sub

Regards,
Peter T

"Karan" <(E-Mail Removed)> wrote in message
news:57381267-F993-4185-9AB9-(E-Mail Removed)...
> Duke,
> Thanks for the help. But this is not what I'm looking for.
> I'm looking for a Macro that does the same as the following windows

process:
> Click on a cell and click on "Format cells", then on custom format

category.
> In the type the custom format is "String" ###0.0.
>
> What I'm trying to achieve is that the "String" should be a variable. The
> end result of such a format is a cell which displays a number along with a
> string. However if you click on the cell, it only has a number as a value.
> Hence you can add/ subtract such cells even though it has a number and a
> string.
>
> For example the string could be something like "Kisses". In such a cell if
> you put a number 10, then it will show up as "10 Kisses" in the cell. You

can
> format many cells and then add all cells to get a sum of all kisses
>
> Cheers, Karan
>
>
> "Duke Carey" wrote:
>
> > from the Help file
> >
> > Worksheets("Sheet1").Range("A17").NumberFormat = "General"
> > Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
> > Worksheets("Sheet1").Columns("C"). _
> > NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
> >
> >
> >
> > "Karan" wrote:
> >
> > > Using the format cell dialog box one can choose Custom Format and give

the
> > > format as
> > >
> > > "String" ###0.0
> > >
> > > The end result is a cell which has a number and text (String) in it,

but
> > > when you click on the contents of the cell you can only see the number

and
> > > cannot see the text (as it is in the format)
> > >
> > > However I don't want to to do this manually for each cell as the

string
> > > changes for each cell.
> > >
> > > I'm trying to figure out how a macro could set a custom format of a

cell to
> > > something like "String from RC[-5]" ###0.0
> > >
> > > Using something like
> > > X = "String from RC[-5] " & " ###0.0"
> > > Y = "=RC[-11]"
> > > ActiveCell = format(Y, X)
> > >
> > > ends up showing both the string and the number in the cell, instead of
> > > having the string in the format and not in the cell.
> > >
> > > How can one put define a custom number format with a variable "String"

in
> > > the format?



 
Reply With Quote
 
=?Utf-8?B?S2FyYW4=?=
Guest
Posts: n/a
 
      13th Aug 2007
ALRIGHTY! Managed it finally by using the following:

Dim A As String

ActiveCell.Formula = "=RC[-5]"

A = ActiveCell.Offset(0, -11).Value

ActiveCell.NumberFormat = """" & A & """" & " ###0.0"


Thanks for all the help.

Cheers, Karan

"Bob Phillips" wrote:

> Does this do it
>
> X = """String from RC[-5] """ & " ###0.0"
> Y = "=RC[-11]"
> ActiveCell.Formula = Y
> ActiveCell.NumberFormat = X
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Karan" <(E-Mail Removed)> wrote in message
> news:C9C2B28A-8067-453B-80AA-(E-Mail Removed)...
> > Hi Bob...thanks for this. However there is still one problem because of
> > which
> > this doesnot work.
> > The value of X here turns out to be "String ###0.0"....and this is not a
> > valid format. It has to be ""String" ###0.0"
> > I tried using Chr(34) instead of a " but that isn't working. This is what
> > I
> > did:
> >
> > X = "Chr(34) String Chr(34)" & " ###0.0"
> > Y = "=RC[-11]"
> > ActiveCell.Formula = Y
> > Activecell.NumberFormat = X
> >
> > Any idea how I could pass an " in the Number format?
> >
> > "Bob Phillips" wrote:
> >
> >> X = "String from RC[-5] " & " ###0.0"
> >> Y = "=RC[-11]"
> >> ActiveCell.Formula = Y
> >> Activecell.NumberFormat = X
> >>
> >> --
> >> HTH
> >>
> >> Bob
> >>
> >> (there's no email, no snail mail, but somewhere should be gmail in my
> >> addy)
> >>
> >> "Karan" <(E-Mail Removed)> wrote in message
> >> news:C1F77F2C-3263-4367-A285-(E-Mail Removed)...
> >> > Using the format cell dialog box one can choose Custom Format and give
> >> > the
> >> > format as
> >> >
> >> > "String" ###0.0
> >> >
> >> > The end result is a cell which has a number and text (String) in it,
> >> > but
> >> > when you click on the contents of the cell you can only see the number
> >> > and
> >> > cannot see the text (as it is in the format)
> >> >
> >> > However I don't want to to do this manually for each cell as the string
> >> > changes for each cell.
> >> >
> >> > I'm trying to figure out how a macro could set a custom format of a
> >> > cell
> >> > to
> >> > something like "String from RC[-5]" ###0.0
> >> >
> >> > Using something like
> >> > X = "String from RC[-5] " & " ###0.0"
> >> > Y = "=RC[-11]"
> >> > ActiveCell = format(Y, X)
> >> >
> >> > ends up showing both the string and the number in the cell, instead of
> >> > having the string in the format and not in the cell.
> >> >
> >> > How can one put define a custom number format with a variable "String"
> >> > in
> >> > the format?
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The formatting is too complex =?Utf-8?B?RE1H?= Microsoft Word Document Management 1 21st Aug 2007 01:15 PM
Formatting too complex =?Utf-8?B?c3Vyb29yYQ==?= Microsoft Word Document Management 3 25th Jun 2007 09:09 AM
Formula help for complex formatting. =?Utf-8?B?U0Nyb3dsZXk=?= Microsoft Excel Worksheet Functions 6 29th Oct 2005 03:06 AM
Complex formatting help lotto@the.com Microsoft Excel Programming 1 19th May 2005 03:17 AM
complex cell formatting using VBA jon Microsoft Excel Programming 2 18th Feb 2004 12:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:15 PM.