LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default In VBA how to select the right format for a range

Hi,
I'm trying to change format depending the data in a range.
In the cell D10 a "signe $%#", will tell vba to select the right format like
$ or % or #, etc.
The format need to change the range D11:D17

Exemple if D10 show: $ the range will be change to currency, if the cell D10
show % the range will change to % with 2 decimal.

I did something like this:

Sub FORMATCol()
Dim Col As Range
For Each Col In Range("D11:D70")
If Range("D10") = "$" Then
Col.NumberFormat = "$#,##0"
End If
Next
' Note: Section if not $ change for #
For Each Col In Range("D11:D70")
If Range("D10") = "#" Then
Col.NumberFormat = "#,##0"
End If
Next

End Sub

Problem is: I dont know how to tell the sub to select the right format IF
D10 =$ or #
I tried to add another IF (see the line after the ' ) in it, however it's
not working. Can you explain how to to this? Thank you

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
Select a Range and Format Jaina WIlliams Excel Programming 3 March 16th 05 07:09 PM
When I select "format cells", the format dialog box does not disp. Andy S. Excel Worksheet Functions 2 November 23rd 04 03:49 AM
Select Sheet then Select Range Gee[_2_] Excel Programming 3 May 27th 04 10:10 PM


All times are GMT +1. The time now is 05:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"