Excel Array Issue

Dear Experts,

I download data from one system, import it into Excel and run a number of macros over it to get it into a format I can send out for review.  One of the macros looks for the beginning of the data and the end of the data, copies it and transposes it into Sheet 2.  However, the macro only looks for one instance of 'Assigned unit' and in some instances there are two instances of it.  When a second instance of 'Assigned unit' is found it is treated as the start of the next block of data.

I have included an example of the data I use as well as the macro.

Thanks
Array-Problem.xlsm
Sonia BowditchInformation Security OfficerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
What is the question?
0
Sonia BowditchInformation Security OfficerAuthor Commented:
I would like the array to include the additional 'Assigned Unit' and move on if not.

Thanks.
0
Saqib Husain, SyedEngineerCommented:
Can you identify that in the given file?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Sonia BowditchInformation Security OfficerAuthor Commented:
I have amended the attached file and highlighted the 'Assigned Unit' in yellow.  When the macro is run all the data I copied transposed to Sheet 2.  I would like an additional column also titled 'Assigned Unit' which would be populated only if a second assigned unit is present.
Array-Problem.xlsm
0
Saqib Husain, SyedEngineerCommented:
Sub FormatRawData()
'Takes the data from Raw worksheet and formats it into rows and copies it to the Formatted worksheet

Dim rFind1 As Range, rFind2 As Range, c As Long, i As Long

Sheets("Sheet2").Select
    Range("A2:O9").Select
    Selection.Clear
    Range("A2").Select

Application.ScreenUpdating = False

With Sheet1.Range("A5", Sheet1.Range("A5").End(xlDown))
    .TextToColumns Destination:=.Cells(1), DataType:=xlDelimited, Other:=True, OtherChar:="="
    Set rFind1 = .Cells(1, 1)
    au = 0
    For i = 1 To WorksheetFunction.CountIf(.Cells, "*Operator ID*")
        Set rFind2 = .Find(What:="Assigned unit", After:=rFind1, LookAt:=xlPart, _
                           MatchCase:=False, SearchFormat:=False)
        If Not rFind2 Is Nothing Then
            Range(rFind1.Offset(, 1), rFind2.Offset(, 1)).Copy
            Sheet2.Range("B" & Rows.Count).End(xlUp)(2).PasteSpecial Transpose:=True
            Sheet2.Range("A" & Rows.Count).End(xlUp)(2).Value = Range(rFind1, rFind2).Rows.Count
            If rFind2.Offset(1) = rFind2 Then
            Sheet2.Range("B" & Rows.Count).End(xlUp).End(xlToRight).Offset(, 1).Value = rFind2.Offset(1, 1)
            Set rFind1 = rFind2.Offset(2)
            Else
            Set rFind1 = rFind2.Offset(1)
            End If
        End If
    Next i
End With

With Sheet2
    c = WorksheetFunction.Max(.Columns(1))
    For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row
        If .Cells(i, 1) < c Then
            .Cells(i, 5 + .Cells(i, 1) - 11).Resize(, c - .Cells(i, 1)).Insert Shift:=xlShiftToRight
        End If
    Next i
    .Columns(1).Delete
    .Range("A1:B1").Value = Array("Operator ID", "Name")
    .Range("C1").Resize(, c - 10).Value = "Active profile"
    .Range("C1").Offset(, c - 10).Resize(, 8).Value = _
                Array("Enable status", "Re-enable date", "Approval Status", "Last changed", _
                      "Last sign-on", "Calculated pwd", "One-time password", "Assigned unit")
End With

Application.ScreenUpdating = True

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sonia BowditchInformation Security OfficerAuthor Commented:
Works perfectly.  Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.