Results 1 to 5 of 5

Custom Format Cells

Threaded View

Gos-C Custom Format Cells 01-29-2011, 12:00 PM
Cutter Re: Custom Format Cells 01-29-2011, 12:41 PM
Marcol Re: Custom Format Cells 01-29-2011, 01:28 PM
Gos-C Re: Custom Format Cells 01-29-2011, 02:55 PM
Marcol Re: Custom Format Cells 01-29-2011, 02:58 PM
  1. #1
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Question Custom Format Cells

    Hi all,

    I have the following code in a module, which I call from another code:

    Option Explicit
    Sub Format_Columns_2()
        Range("D5", Range("D5").End(xlDown)).Select
        Selection.NumberFormat = "000000"
        Range("E5", Range("E5").End(xlDown)).Select
        Selection.NumberFormat = "0000000000"
        Range("G5", Range("G5").End(xlDown)).Select
        Selection.NumberFormat = "00000000"
        Range("I5", Range("I5").End(xlDown)).Select
        Selection.NumberFormat = "_(* #,##0.0_);_(* (#,##0.0);_(@_)"
        Range("J5", Range("J5").End(xlDown)).Select
        Selection.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(@_)"
        Range("L5", Range("L5").End(xlDown)).Select
        Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(@_)"
        Range("A:G,K:K,M:M").Select
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("A1").Select
    End Sub

    The values in column E varies in length from 1 to 10 numeric characters, e.g., 1234567, or (in a very few cases), consist of 15 alphanumeric characters – e.g., 00000000A987654.

    The code is formatting column E to number format “0000000000” but the alphanumeric values still show the 15 characters.

    I tried to modify it as follows:

    Option Explicit
    Sub Format_Columns_2()
    Dim LastRow As Integer, vRow As Integer
    LastRow = Range("E" & Rows.Count).End(xlUp).Row
    For vRow = 5 To LastRow - 16
       If Len(Range("E" & vRow)) > 10 Then
        Range("E" & vRow).Value = Right("E" & vRow, 10)
       End If
      Next
        Range("D5", Range("D5").End(xlDown)).Select
        Selection.NumberFormat = "000000"
        Range("E5", Range("E5").End(xlDown)).Select
        Selection.NumberFormat = "0000000000"
        Range("G5", Range("G5").End(xlDown)).Select
        Selection.NumberFormat = "00000000"
        Range("I5", Range("I5").End(xlDown)).Select
        Selection.NumberFormat = "_(* #,##0.0_);_(* (#,##0.0);_(@_)"
        Range("J5", Range("J5").End(xlDown)).Select
        Selection.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(@_)"
        Range("L5", Range("L5").End(xlDown)).Select
        Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(@_)"
        Range("A:G,K:K,M:M").Select
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("A1").Select
    End Sub

    But it is not working.

    Can someone help me fix it, please.

    Thank you,
    Gos-C
    Last edited by Gos-C; 01-29-2011 at 02:56 PM.
    Using Excel 2010 & Windows 10
    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

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