This macro:ReadVxInput() processes the text/csv file excel-input.txt and distributes the record fields to various workheets according to the floor number.
Instead of reading the file directly into an Excel worksheet, it reads the file, one line (record) at a time into the variable MyRecord (Line Input #1, MyRecord). Each record/line consists of ten comma separated fields.
The fields are examined using the following repeated code:
pos = InStr(1, MyRecordCopy, ",", vbTextCompare)
floor = Trim(Left(MyRecordCopy, pos - 1))
where pos is used to find the left most comma and string to the left of the comma is copied to the associated variable (floor in this case).
After the field is copied, the line is cut from the left up to and including the found comma position.
MyRecordCopy = Trim(Mid(MyRecordCopy, pos + 1))
-----------------------------------------------------------
the destination sheet is determined by the contents of FLOOR variable:
Sheets(floor).Activate
the destination cell is found by Private Function FindLocation(...): ActiveSheet.Cells.Find(What:=textToFind...).Activate
There are many areas were that code can be changed. For instance there are seven, such as: pos = InStr(1, MyRecordCopy, ",", vbTextCompare)
floor = Trim(Left(MyRecordCopy, pos - 1))
where the commas are found in the string, then string trimmed and a value copied to a variable.
The find comma/trim & copy can be replaced with the VBA Split function:
Fields=Split(MyRecord,",") results in a ten element array of values where Floor is element 1, typeStr= 2, etc.
Bookmarks