ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Setting cell format based on format codes (https://www.excelbanter.com/excel-programming/418384-setting-cell-format-based-format-codes.html)

Hans Knudsen

Setting cell format based on format codes
 
I have some format codes in G14:G36 like:
G14: #.##0..
G15: _(* #.##0_);_(* (#.##0);_(* "-"_);_(@_)
G16: "+45"## ## ## ##
etc.

and would like a macro that can take the format codes in G14:G36 and create
these formats in cells I14:I36.

Will someone help me?

Regards
Hans Knudsen



Rick Rothstein

Setting cell format based on format codes
 
If I understand your request correctly, this macro should do what you
want...

Sub ApplyFormats()
Dim C As Range
For Each C In Range("G14:G36")
C.Offset(0, 2).NumberFormat = C.Value
Next
End Sub

--
Rick (MVP - Excel)


"Hans Knudsen" wrote in message
...
I have some format codes in G14:G36 like:
G14: #.##0..
G15: _(* #.##0_);_(* (#.##0);_(* "-"_);_(@_)
G16: "+45"## ## ## ##
etc.

and would like a macro that can take the format codes in G14:G36 and
create these formats in cells I14:I36.

Will someone help me?

Regards
Hans Knudsen




Hans Knudsen

Setting cell format based on format codes
 
Rick Rothstein
Thank you.
Yes you understood me correctly, but there are some problems, which I think
is due to the fact that my location is Denmarkand as you may (not) know we
use

.. (point) as thousand separator
, (comma) as decimal separator

For example, when I run your macro on cells with the folllowing formats:
#.##0,00 "kroner" and
#.##0 "kroner"
I get the results
1500,000 kroner

1500,0 kroner


Date formats: For day, mont and year we use "dd-mm-مممم" where I guess you
would use "dd-mm-yyyy", that is م instead of y. For example the code
"mmm-مم" becomes nov مم after running your macro on a cell containg a date
i November.

I did not think of all these problems when I asked the question., and I
wonder if it is somewhat too involved.

Hans





"Rick Rothstein" wrote in message
...
If I understand your request correctly, this macro should do what you
want...

Sub ApplyFormats()
Dim C As Range
For Each C In Range("G14:G36")
C.Offset(0, 2).NumberFormat = C.Value
Next
End Sub

--
Rick (MVP - Excel)


"Hans Knudsen" wrote in message
...
I have some format codes in G14:G36 like:
G14: #.##0..
G15: _(* #.##0_);_(* (#.##0);_(* "-"_);_(@_)
G16: "+45"## ## ## ##
etc.

and would like a macro that can take the format codes in G14:G36 and
create these formats in cells I14:I36.

Will someone help me?

Regards
Hans Knudsen





Rick Rothstein

Setting cell format based on format codes
 
I'm afraid I have no experience with international formatting issues, so I
can't address what you have said directly; however, it is my belief
(although I could be wrong) that if you use locally correct formatting
pattern strings in your cells, then the code I posted should work. I don't
know what to say beyond that. Perhaps someone with more international excel
experience will come along and add to my comments. It's the weekend, so the
number of volunteers answering questions is small right now; so I would say
if you don't hear anything by Tuesday, repost your question (mentioning the
international formatting angle) and someone should be able to answer it
then.

--
Rick (MVP - Excel)


"Hans Knudsen" wrote in message
...
Rick Rothstein
Thank you.
Yes you understood me correctly, but there are some problems, which I
think is due to the fact that my location is Denmarkand as you may (not)
know we use

. (point) as thousand separator
, (comma) as decimal separator

For example, when I run your macro on cells with the folllowing formats:
#.##0,00 "kroner" and
#.##0 "kroner"
I get the results
1500,000 kroner

1500,0 kroner


Date formats: For day, mont and year we use "dd-mm-مممم" where I guess you
would use "dd-mm-yyyy", that is م instead of y. For example the code
"mmm-مم" becomes nov مم after running your macro on a cell containg a
date i November.

I did not think of all these problems when I asked the question., and I
wonder if it is somewhat too involved.

Hans





"Rick Rothstein" wrote in message
...
If I understand your request correctly, this macro should do what you
want...

Sub ApplyFormats()
Dim C As Range
For Each C In Range("G14:G36")
C.Offset(0, 2).NumberFormat = C.Value
Next
End Sub

--
Rick (MVP - Excel)


"Hans Knudsen" wrote in message
...
I have some format codes in G14:G36 like:
G14: #.##0..
G15: _(* #.##0_);_(* (#.##0);_(* "-"_);_(@_)
G16: "+45"## ## ## ##
etc.

and would like a macro that can take the format codes in G14:G36 and
create these formats in cells I14:I36.

Will someone help me?

Regards
Hans Knudsen







All times are GMT +1. The time now is 11:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com