VBA array loop nesting

WarPigl3t

Well-known Member
Joined
May 25, 2014
Messages
1,611
Hey yall. Long time no see. I must be out of practice. Can yall help me out with a thing I'm working on for my job? I shrank the code down and the input data so that it wouldn't be too much too read. I only left the relevant code and relevant input data.

Data is in Microsoft word; However, that doesn't matter because I'm using a UserForm that is available in both Word and Excel, and I haven't even gotten to the part in the code where I output the data from the form into the word document. That will come after I figure out this current issue. I run the macro showForm(), and a form pops up. I paste some data into the form and click the submit button. It will split each line into an individual element in an array. For each element, check if it says "History of Present Illness:". Once found, it will add all following data into a different array. It will stop adding once it finds "Major Problems:"

Here is some sample data that I paste into the UserForm...
Ms. Jennifer Lopez is a 51 year old female who presents for follow up on chronic kidney disease. Patient complains of for high blood pressure in dialysis and has been taking hydralazine prior to each treatment. No nausea vomiting no chest pain. She is awaiting the evaluation for transplant with Methodist Hospital in San Antonio.

History of Present Illness:
1. Hypertension
2. Coronary Artery Disease

Major Problems:

The output into getHxPresentIllness = aryHxPresentIllness() should be the following elements:
1. Hypertension
2. Coronary Artery Disease

Code:
[SIZE=2][FONT=arial]Sub showForm()[/FONT]
[FONT=arial]    frmProgressNote.Show[/FONT]
[FONT=arial]End Sub

Private Sub btnCancel_Click()[/FONT]
[FONT=arial]    txtProgressNote.Value = ""[/FONT]
[FONT=arial]    frmProgressNote.Hide[/FONT]
[FONT=arial]End Sub[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]Private Sub btnProgressNote_Click()[/FONT]
[FONT=arial]    If txtProgressNote.Value = "" Then Exit Sub[/FONT]
[FONT=arial]    Call runAllMacros(txtProgressNote.Value)[/FONT]
[FONT=arial]    txtProgressNote.Value = ""[/FONT]
[FONT=arial]    frmProgressNote.Hide[/FONT]
[FONT=arial]End Sub[/FONT]
[FONT=arial]
[/FONT]

[FONT=arial]Sub runAllMacros(progressNote)
[/FONT]
[FONT=arial]    primaryDx = findPrimaryDx(progressNote)
    'Other code continues...
End Sub

[/FONT]
[FONT=arial]Function findPrimaryDx(progressNote)[/FONT]
[FONT=arial]    aryHxPresentIllness = getHxPresentIllness(progressNote)    
   aryAssessments = getAssessments(progressNote) 'Does the same thing as the line above but for a different section of the input data.[/FONT]
[FONT=arial]    aryAllProblems = getAllProblems(aryHxPresentIllness, aryAssessments) 'Concatinates both arrays into 1 array.[/FONT]
[FONT=arial]    'Other code continues...
End Function

[/FONT]
[FONT=arial]Function getHxPresentIllness(progressNote)[/FONT]
[FONT=arial]    mySplit = Split(progressNote, vbCr)[/FONT]
[FONT=arial]    Dim aryHxPresentIllness() As Variant[/FONT]
[FONT=arial]    a = 0[/FONT]
[FONT=arial]    boolFoundHxPresentIllness = False[/FONT]

[FONT=arial]    s = 0[/FONT]
[FONT=arial]    lastS = UBound(mySplit)[/FONT]
[FONT=arial]    Do Until s > lastS[/FONT]
[FONT=arial]        test = Trim(mySplit(s))[/FONT]
[FONT=arial]        s = s + 1[/FONT]
[FONT=arial]    Loop[/FONT]

[FONT=arial]    For Each myLine In mySplit[/FONT]

[FONT=arial][COLOR=#ff0000][B]        'WORKING ON THIS CODE!!![/B][/COLOR][/FONT]
[FONT=arial][COLOR=#0000ff]        If LCase(myLine) Like "*" & "history of present illness:" Then[/COLOR][/FONT]
[FONT=arial][COLOR=#0000ff]            boolFoundHxPresentIllness = True[/COLOR][/FONT]
[FONT=arial][COLOR=#0000ff]        End If[/COLOR][/FONT]
[FONT=arial][COLOR=#0000ff]        If LCase(Trim(myLine)) = "history of present illness:" Then[/COLOR][/FONT]
[FONT=arial][COLOR=#0000ff]            boolFoundHxPresentIllness = True[/COLOR][/FONT]
[FONT=arial][COLOR=#0000ff]        End If[/COLOR][/FONT]



[FONT=arial]        If boolFoundHxPresentIllness = True Then[/FONT]
[FONT=arial]            If LCase(myLine) Like "*" & "major problems:" & "*" Then[/FONT]
[FONT=arial][COLOR=#0000ff]                getHxPresentIllness = aryHxPresentIllness()[/COLOR][/FONT]
[FONT=arial]                Exit Function[/FONT]
[FONT=arial]            End If[/FONT]
[FONT=arial]            If Trim(myLine) <> "" Then[/FONT]
[FONT=arial]                ReDim Preserve aryHxPresentIllness(a)[/FONT]
[FONT=arial]                aryHxPresentIllness(a) = myLine[/FONT]
[FONT=arial]                a = a + 1[/FONT]
[FONT=arial]            End If[/FONT]
[FONT=arial]        End If[/FONT]
[FONT=arial]    Next myLine[/FONT]

[FONT=arial]    'If macro goes this far, something is wrong.  Maybe the progress note is missing _[/FONT]
[FONT=arial]    History of Present Illness: or Major Problems:[/FONT]
[FONT=arial]    msgError = MsgBox("If macro goes this far, something is wrong.  Maybe the progress note is missing" _[/FONT]
[FONT=arial]    & vbNewLine & "History of Present Illness: or Major Problems:" & vbNewLine _[/FONT]
[FONT=arial]    & "Macro must terminate immediately!")[/FONT]
[FONT=arial]    End[/FONT]
[FONT=arial]End Function[/FONT]
[/SIZE]
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
SOLVED
The answer was to change...
mySplit = Split(progressNote, vbCr)

To this...
mySplit = Split(progressNote, Chr(11))

Guess I just needed to get some sleep to figure it out. Thanks anyway.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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