Hi all,

I don't have a ton of VBA experience, so I was hoping I could get some ideas from others. I have a text document resulting from print statements in the following format:

Set CurrentRng = Range("NamedRange")
Print #1, .Name & Chr(9) & "NamedRange" & Chr(9) & CurrentRng

So the data might look like this in the text file:

Sheet Name Named Rng Value
Sheet 1 Name 1 2
Sheet 1 Name 2 3
Sheet 1 Name 2 4

Notice that there are 2 values for the the cell range "Name 2" (Named range encompasses two cells).

I am trying to take the values from the text document and paste them into the correct cells (i.e. if values "3" and "4" were in cells A4 and A5, respectively, in the original document, I want to be able to return them to those positions but using the named range so the results are unaffected by any edits to the excel document)

Here's my code:

Sub Test_Input()

Dim InData As String
Dim SheetName As String
Dim NamedRng As String
Dim NewVal As String
Dim WS As Worksheet
Dim Target As String

Open "TESTFILE" For Input As #1

Do Until EOF(1)
    Line Input #1, InData
    
    SheetName = GetSubString(InData, Chr(9), 1)
    NamedRng = GetSubString(InData, Chr(9), 2)
    NewVal = GetSubString(InData, Chr(9), 3)

    Set WS = ThisWorkbook.Sheets(SheetName)
    
    Target = NamedRng
    
    WS.Range(Target) = NewVal
    
Loop

Close #1
End Sub
Where the GetSubString function is just pulling the 3 fields in the text document.

I'm running into a problem when two entries have the same named range, as in the example above. So all the cells in the range "Name 2" will populate as 4, instead of the first populating as 3 and the second populating as 4. I know my code currently does nothing to separate these out, I'm having difficulty thinking of a way to get my desired result. Any ideas?

Thanks in advance!