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
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
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"
Bookmarks