Results 1 to 16 of 16

[Solved] Error checking for 0 in script

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-16-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    116

    [Solved] Error checking for 0 in script

    Firstly this post rlates to this threadhttp://www.excelforum.com/excel-gene...-one-cell.html but for clarity am starting a new thread as this will be a long post.

    I am using a version of a script posted by Paul in that thread, the prupose of which was to split numbers across cells from the format
    7-2-1-2 $86550.00
    Option Explicit
    
    Sub flebber()
    Dim arr As Variant, i As Long
    With Sheets("Sheet1")
    arr = .Range("A1:A" & .UsedRange.Rows.Count)
    For i = 1 To UBound(arr)
        .Range("B" & i & ":E" & i).Value = Split(arr(i, 1), "-")
    Next i
    End With
    End Sub
    I need to introduce some error checking or similar as I now have found that when a field contains to many zero's and no dollars macro cannot complete. example formats
    1-0-0-0 and 0-0-0-0
    I would need the columns to then contain values so originating colums 0.00 and all other columns 0. maybe could use default values?

    This is the script I am currently using.

    ' Split numbers across columns leaving dollar in originating column
        With Sheets("Sheet1")
        Dim arr As Variant, x As Long
        arr = .Range("AH1:AH" & .UsedRange.Rows.Count)
        For x = 1 To UBound(arr)
        .Range("AI" & x & ":AL" & x).Value = Split(Left(arr(x, 1), InStr(arr(x, 1), " ")), "-")
        .Range("AH" & x).Value = Mid(arr(x, 1), InStr(arr(x, 1), "$") + 1)
        Next x
        End With
        ' ensuring format is number not number stored as text
        With Sheets("Sheet1")
        NumberAmmend = Cells(Rows.Count, 1).End(xlUp).Row
        With .Range(.Cells(2, "AI"), .Cells(NumberAmmend, "AL"))
            .NumberFormat = "General"
            .Value = .Value
        End With
        End With
        ' ensuring number is saved in dollar format
        With Sheets("Sheet1")
        NumberAmmend = Cells(Rows.Count, 1).End(xlUp).Row
        With .Range(.Cells(2, "AH"), .Cells(NumberAmmend, "AH"))
            .NumberFormat = "$#,##0.00"
            .Value = .Value
        End With
        End With
        LastRow4 = Range("AH" & Rows.Count).End(xlUp).Row
        Range("AH2:AH" & LastRow).NumberFormat = "$#,##0.00"
    Last edited by flebber; 08-03-2010 at 08:26 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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