MACRO or Formula to divide data based on Spacing

richmcgill

Board Regular
Joined
Feb 4, 2019
Messages
87
Office Version
  1. 2016
Platform
  1. Windows
None of this is classified and is open to the public.

We have to load borrower data to the governments SCRA database to look for active service members.
The file that is returned has very specific spacing requirements to be able to use the information. The return file is a text file I need to get into an Excel spreadsheet. Using the Data Wizard is slow and rime consuming.
Anyone can access the user guide at their website SCRA
A typical file looks like this but 10's of thousands rows long. No headers. The headers are the Field Names.

Is there a way via formula or MACRO to add the headers to each column as well as split up the data based on its spacing?

1668105334243.png

There is a guide that helps determine the spacing aka hope to break up the return data.
1668105121902.png


1668105187822.png

1668105225097.png


Here are the headers and spacing in a spreadsheet format.

MORTGAGOR SSNMORTGAGOR BIRTH DATEMORTGAGOR LAST NAMEMORTGAGOR FIRST NAMELOAN NUMBERActive Duty Status DateBlankOn Active Duty on the Active Duty Status DateLeft Active Duty <= Days from the Active Duty Status DateNotified of Active Duty Recall on Active Duty Status DateActive Duty End DateMatch Result CodeErrorDate of MatchActive Duty Begin DateEID Begin DateEID End DateService ComponentEDI Service ComponentMiddle NameCertificate ID
1-910-1717-2344-6364-9192-99100101102103104-111112113114-121122-129130-137138-145146-147148-149150-169170-184
 

Attachments

  • Screenshot 2022-11-10 115127.jpg
    Screenshot 2022-11-10 115127.jpg
    109.9 KB · Views: 17
  • Screenshot 2022-11-10 115146.jpg
    Screenshot 2022-11-10 115146.jpg
    78.2 KB · Views: 12

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
None of this is classified and is open to the public......Anyone can access the user guide at their website SCRA
A typical file looks like this but 10's of thousands rows long. No headers. The headers are the Field Names.

Do you mean to say that there is a public website where any random internet user can dump the full names, social security numbers, DOB, and service dates for active duty service personnel? How is that not illegal?
 
Upvote 0
Do you mean to say that there is a public website where any random internet user can dump the full names, social security numbers, DOB, and service dates for active duty service personnel? How is that not illegal?

You have to have a business purpose but you can go to the site and look at the USER guide without an account. We have an account and registered with our business. Not everyone can load information to the site and get service member information in return.
 
Upvote 0
Well that's good to know, at least. Since the data is highly structured you can extract the data fields in a number of ways.

The most expedient way would probably to use the macro recorder and record yourself opening the file and then use the 'Text to columns' wizard to import the data. Here's a macro I recorded following that method.

VBA Code:
Sub RecordedImportMacro()
'
' RecordedImportMacro Macro
'
'
    Workbooks.OpenText Filename:="C:\Temp\DataDump.txt", Origin:=437, StartRow:=1, DataType:=xlFixedWidth, _
                       FieldInfo:=Array(Array(0, 1), Array(9, 1), Array(17, 1), Array(43, 1), Array(63, 1), _
                       Array(85, 1), Array(99, 1), Array(100, 1), Array(101, 1), Array(102, 1), Array(103, 1), _
                       Array(111, 1), Array(112, 1), Array(113, 1), Array(121, 1), Array(129, 1), Array(137, 1), _
                       Array(145, 1), Array(147, 1), Array(149, 1), Array(169, 1)), TrailingMinusNumbers:=True

    Sheets("DataDump").Select
    Sheets("DataDump").Move Before:=Workbooks("Test.xlsm.xlsx").Sheets(1)
    Columns.AutoFit
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top