coveredinbutter
New Member
- Joined
- Dec 20, 2021
- Messages
- 19
- Office Version
- 365
- Platform
- Windows
Hi All,
I have the following code working to read in a .csv file to another sheet based on a specific pattern:
I want to replace the first section with a loop that I also have working (below) that fills an array and instead of having it define rx.pattern just once and check for just one pattern, have it loop through all the values in the array and read in the file based on each pattern in the array. I can't seem to get this last part working. Hopefully, that makes sense.
I have the following code working to read in a .csv file to another sheet based on a specific pattern:
VBA Code:
With wsSM
For i = 2 To .UsedRange.Rows.Count
If Cells(i, 1).Value = group Then
teamPattern = Cells(i, 2).Value
Exit For
Else
Cells(i, 2).Value = Cells(i, 2).Value
End If
Next i
End With
rx.Pattern = teamPattern
'disable file read if people.csv moved to sharepoint
Open filePath For Input As #1
Do Until EOF(1)
Line Input #1, line
splitLine = split(line, ",")
If cTeam = -1 Then
For i = 0 To UBound(splitLine)
If splitLine(i) = "Team" Then cTeam = i
If splitLine(i) = "Deactivated" Then cDeact = i
If splitLine(i) = "Enable Scheduling" Then cSched = i
If splitLine(i) = "Skill Mappings" Then cSkills = i
If splitLine(i) = "Employee ID" Then cID = i
If splitLine(i) = "First Name" Then cFName = i
If splitLine(i) = "Last Name" Then cLName = i
Next i
End If
On Error Resume Next
If splitLine(cDeact) = "" And splitLine(cSched) = "TRUE" Then
If rx.Test(splitLine(cTeam)) Then
skills = split(splitLine(cSkills), ";")
wsData.Range("A" & x) = splitLine(cID)
wsData.Range("B" & x) = splitLine(cFName) & " " & splitLine(cLName)
wsData.Range("C" & x) = splitLine(cTeam)
wsData.Range("D" & x) = group
mc = 5
For m = LBound(skills) To UBound(skills)
wsData.Cells(x, mc).Value = skills(m)
mc = mc + 1
Next m
x = x + 1
ContinueDo:
End If
End If
Loop
Close #1
I want to replace the first section with a loop that I also have working (below) that fills an array and instead of having it define rx.pattern just once and check for just one pattern, have it loop through all the values in the array and read in the file based on each pattern in the array. I can't seem to get this last part working. Hopefully, that makes sense.
VBA Code:
For Each gp In arr_Groups
With wsSM
For i = 2 To .UsedRange.Rows.Count
If Cells(i, 1).Value = gp Then
customPattern(g) = Cells(i, 2).Value
g = g + 1
Exit For
Else
Cells(i, 2).Value = Cells(i, 2).Value
End If
Next i
End With
Next gp