+ Reply to Thread
Results 1 to 4 of 4

Create flat file from data download

Hybrid View

msmithdynamicsgp Create flat file from data... 05-20-2011, 01:04 PM
watersev Re: Create flat file from... 05-20-2011, 03:56 PM
msmithdynamicsgp Re: Create flat file from... 05-24-2011, 06:37 PM
msmithdynamicsgp Re: Create flat file from... 06-12-2011, 09:54 PM
  1. #1
    Registered User
    Join Date
    02-24-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Create flat file from data download

    I am having some difficulty taking a raw data download and making it into a flat file. Would it be possible to help me with the code to generate the flat file from exisitng data?

    I attached a sample spreadsheet with input as I get it (merged and missing two columns of data) and also an output version showing what I hope to eventually achieve.

    I added a column for "Site" and one for "Therapy". Getting those new columns populated in VBA is the toughest challenge for me (but by no means the only one). Another part I struggle with a bit is that some cells are merged.

    Any help is greatly appreciated.

    -Michael
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Create flat file from data download

    hi, Michael, it can be done this way, run code "test"

    PS. I did not understand why Perkins, Ruby became Person 13. On the result sheet he will remain Perkins, Ruby.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    02-24-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Create flat file from data download

    watersev,

    Thank you very much for providing this working solution. I tested it on live data and the program produced good output. Amazingly fast and clean compared to anything I could have come up with!

    The only difference I see in matching the data is that the flat file is off a small amount per site due to rounding and I am not sure quite where to adjust the code. After I figure that out, it is letter perfect.

    Thanks again!

    -Michael

  4. #4
    Registered User
    Join Date
    02-24-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Create flat file from data download

    I have one last question on this problem. Looking at the msmithdynamicsgp.xlsm sample posted above:

    In the 'input' sheet, I found that column Q (Supplies) has a precision of four decimal places.

    The corresponding 'output' sheet in column J (Supplies) is rounded off to two decimal places.

    How can I revise this so that the level of precision is not lost? i.e. so that the output sheet in column j keeps all four decimal places?

    I tried changing the data type Long below to Double, but that did not change the output at all. I also tried messing with the numberformat, which I knew had nothing to do with precision.

    Any ideas?



    Option Explicit
    Sub test()
    Dim x, y, col, vl, i As Long, j As Long, m As Integer, site As String, therapy As String
    Application.ScreenUpdating = False: With Sheets("input"): x = .Range(.[a9], .Cells(Rows.Count, "a").End(xlUp).Offset(, 22)): End With
    ReDim y(1 To UBound(x), 1 To 11): col = Array(1, 2, 3, 5, 10, 12, 13, 17, 20): m = 2
    For i = 1 To UBound(x)
        If x(i, 1) = "Therapy:" Then
            If x(i - 2, 1) = "" Then site = x(i - 1, 1)
                therapy = x(i, 2): i = i + 1
            Do
               j = j + 1: y(j, 1) = site: y(j, 2) = therapy
                For Each vl In col
                    m = m + 1: y(j, m) = x(i, vl)
                Next: m = 2: i = i + 1
            Loop Until InStr(1, x(i, 1), "Total:") > 0
    End If
    Next: With Sheets("output").[a2].Resize(j, 11): .Value = y: .Offset(, 6).Resize(, 5).NumberFormat = "0.00": End With
    Application.ScreenUpdating = True: End Sub

+ 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