VBA form to retrieve data based on name and add data to new columns

Woosha

New Member
Joined
Apr 13, 2018
Messages
9
Hello i am new this is my first post, had a look and the site seems very helpful like it so far!

What i want to achieve?
Use patients name and retrieve 2 fields ( got it working but works with Integers only ) - this fields should not be editable

After locating the patient to add in the row in the end for the same patient other info that the user will input.

What i got so far
Code:
Dim id As Integer, i As Integer, j As Integer, flag As Boolean

'Code to retrieve data based on ID - to be changed to string ( patients name )


Sub GetData()


If IsNumeric(UserForm1.TextBox1.Value) Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value


    Do While Cells(i + 1, 1).Value <> ""


        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
            Next j
        End If


        i = i + 1


    Loop


    If flag = False Then
        For j = 2 To 3
            UserForm1.Controls("TextBox" & j).Value = ""
        Next j
    End If


'Else
 '   ClearForm
End If


End Sub


'Sub to Add extra fields on the selected patient


Sub EditAdd()


Dim emptyCol As Long


If UserForm1.TextBox1.Value <> "" Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value
    'emptyCol = WorksheetFunction.CountA(Range("A:Z")) + 1
    emptyCol = WorksheetFunction.CountA(Columns(1)) + 1
    Do While Cells(i + 1, 1).Value <> ""


        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
            Next j
        End If


        i = i + 1


    Loop


    If flag = False Then
        For j = 1 To 3
            Cells(emptyCol, j).Value = UserForm1.Controls("TextBox" & j).Value
        Next j
    End If


End If


End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
This is how the form looks.
Name of text boxes Textbox1 to Textbox10 from top to bot.
fzqLu7
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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