Solved

Macro that will distribute numbers, some of which are shown as ranges, to cells

Posted on 2011-03-18
8
220 Views
Last Modified: 2012-05-11
Please take a look at the attached workbook. I have a file that contains multiple numbers in each cell in a range of 40+ cells . Some of the numbers are expressed as ranges with a dash. I need a macro that will distribute each individual number, stated or implied, to its own cell.

Thanks,
John


DistributeNumbers.xls
0
Comment
Question by:gabrielPennyback
  • 5
  • 3
8 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35167630
Do you do any work yourself?

1,917 question so far! Jeez!
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 35167744
Here.

Kevin
DistributeNumbers.xls
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 35167907
Hey, I'm just getting started! And you ... you are as smart as you are a smart-ass!

Thank you. :-)

John
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35167926
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 35167938
Thanks Kevin. Hey, if I'm not pushing my luck (which of course is one of the things I do best) ... if you could toss off a little macro, that would be awesome. I just like to see the little numbers populate and I've had this issue with arrays ever since I was in first grade.
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 35167961
"Please re-write the description using better punctuation, spelling, and grammar." You and I have to go to a biker bar sometime and see how long it takes us to get beat up. :-)
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35167970
Can I bring my buddy Steve? He's a badass Italian MF who has a nice gun collection.
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35167989
Because I love you so damn much I made an even better UDF that doesn't display "#N/A" and displays "More..." in the last formula cell if there isn't enough room.

Public Function ExpandNumberSequence(ByVal Source As String) As Variant

    Dim Tokens As Variant
    Dim Token As Variant
    Dim SubTokens As Variant
    Dim Index As Long
    Dim Result As Variant
    Dim More As Boolean
   
    Result = Array()
   
    Tokens = Split(Source, ",")
    For Each Token In Tokens
        SubTokens = Split(Trim(Token), "-")
        If UBound(SubTokens) = 0 Then
            ReDim Preserve Result(0 To UBound(Result) + 1)
            Result(UBound(Result)) = Val(SubTokens(0))
        Else
            For Index = SubTokens(0) To SubTokens(1)
                ReDim Preserve Result(0 To UBound(Result) + 1)
                Result(UBound(Result)) = Index
            Next
        End If
    Next Token
   
    If Application.Caller.Columns.Count < UBound(Result) + 1 Then More = True

    ReDim Preserve Result(0 To Application.Caller.Columns.Count - 1)
    For Index = 0 To UBound(Result)
        If IsEmpty(Result(Index)) Then
            Result(Index) = vbNullString
        End If
    Next Index
    If More Then
        Result(UBound(Result)) = "More..."
    End If
   
    ExpandNumberSequence = Result

End Function

Kevin
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question