View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mat P:son[_2_] Mat P:son[_2_] is offline
external usenet poster
 
Posts: 97
Default custom number formats - including text from other cells

If you want to, yes. I'm not entirely sure what you mean by a format like
"R_text from cell_0001" (the syntax looks a bit odd to me), but it's
definitely possible to set a particular number format using VBA code.

Try typing for example 123 or -123 into cell A2, and for example:

\A\B\C $#,##0.00_);[Red]($#,##0.00)

....into cell A1, then run the VBA lines below

Public Sub FormatTest()
' Get data from cell A1
Dim sFormat As String
sFormat = Worksheets("Sheet1").Cells(1, 1).Value

' ...fiddle a little bit more with sFormat here, if you want to

' Format cell A2
Worksheets("Sheet1").Cells(1, 2).NumberFormat = sFormat
End Sub

For more info about cell formatting, please open up the VBA help and search
for terms such as Format Codes, NumberFormat, Format Codes, NumberFormatLocal
etc.

Hope this helps,
/MP

"Nick Smith" wrote:

Hi,

I want to customise a number format such that it use the text of a
particular cell from a different sheet, e.g. R_text from cell_0001.

Can a macro do this?

Thanks,

Nick