+ Reply to Thread
Results 1 to 4 of 4

Format specific columns to currency

  1. #1
    Registered User
    Join Date
    07-15-2008
    Location
    germany
    Posts
    56

    Format specific columns to currency

    PHP Code: 
    Dim message As String
    Dim titleOfWindow 
    As String
    Dim standardRange 
    As String
    Dim rangeSelected 
    As String
    Dim i 
    As Variant
    Dim j 
    As Integer
    Dim ws 
    As Worksheet

    1

    message 
    "Give your range please"
    titleOfWindow "Formatting cells"
    standardRange "X:Z"

    Debug.Print standardRange

    rangeSelected 
    Application.InputBox(messagetitleOfWindowstandardRangeType:=10)
    Debug.Print rangeSelected

    Range
    (rangeSelected).Select
    Selection
    .Style "Currency"
    Selection.NumberFormat "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"

    End Sub 

    Above is my code to select some default column and format it to currency. I tried to enhance the code to automatically get the columns which are selected in the activeworkbook and format them. But in the dialogbox my range is not selected as e.g X:Y but as =$X:$Y and thats why I am not able to implement it.
    Need some suggestions
    Thanks

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Format specific columns to currency

    try this
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-15-2008
    Location
    germany
    Posts
    56

    Re: Format specific columns to currency

    PHP Code: 
    Dim message As String
        Dim titleOfWindow 
    As String
        Dim standardRange 
    As String
        Dim rangeSelected 
    As Range
        Dim i      
    As Variant
        Dim j      
    As Integer
        Dim ws     
    As Worksheet

        i 
    1

        message 
    "Give your range please"
        
    titleOfWindow "Formatting cells"
        
    standardRange "A:D"

        
    Debug.Print standardRange

        Set rangeSelected 
    Application.InputBox(messagetitleOfWindowstandardRangeType:=8)
    Debug.Print rangeSelected

        
    With Range
    (rangeSelected.Address).EntireColumn

            
    .Style "Currency"
            
    .NumberFormat "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
        
    End With
    End Sub 
    I have changed the
    PHP Code: 
    With Range(rangeSelected.Address).Entirerow 
    with
    PHP Code: 
    With Range(rangeSelected.Address).EntireColumn 
    from your code as I want to select the entire column. Your code was very helping thanks a lot for it.
    Perhaps I ask you another question relating the code.

    I am getting the range at the moment through the Inputbox. Is it possible to
    build this code in such a way that the code knows which cells have already been selected. For example I have a workbook open and have selected some cells already and these exactly these cells should be formatted.

    In this way I can get rid of inputbox and my solution would be time saving and dynamic.
    Last edited by adyan76; 02-27-2009 at 03:13 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Format specific columns to currency

    Use Selection
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1