How do I pass a field name in a UserForm as a variable.

USAMax

Well-known Member
Joined
May 31, 2006
Messages
843
Office Version
  1. 365
Platform
  1. Windows
I just learned how to define a Range so I can pass it but I don't know what to call these but field names.

I have a UserForm with several comboboxes and I am searching the sheet to populate each field.

Here is what I've got:
Code:
    'LEAD ENGINEER
    TmpR = SDR                                              'Get the Starting Date Row
    Do While Aws.Cells(TmpR, 1) = DateValue(CurStrDte) And _
             Aws.Cells(TmpR, ALEC) <> ""                    'Is the Lead Eng not blank and does the Starting Date Row match the Starting Date?
        If EngFreeTrghEndDate(Aws, Aws.Cells(TmpR, ALEC), CurStrDte, CurEndDte, TmpR, ALEC) Then
            LeadEngineer.AddItem Aws.Cells(TmpR, ALEC)          'YES: Add the Lead Eng to the list.
        End If
        TmpR = TmpR + 1                                     '     Advance to the next row
    Loop                                                    'CHECK AGAIN
    
    'IMPLEMENTATION ENGINEER
    TmpR = SDR                                              'Get the Starting Date Row
    Do While Aws.Cells(TmpR, 1) = DateValue(CurStrDte) And _
             Aws.Cells(TmpR, AIMC) <> ""                    'Is the Implementation Eng not blank and does the Starting Date Row match the Starting Date?
        If EngFreeTrghEndDate(Aws, Aws.Cells(TmpR, AIMC), CurStrDte, CurEndDte, TmpR, AIMC) Then
            ImplementationEngineer.AddItem Aws.Cells(TmpR, AIMC) 'YES: Add the Implementation Eng to the list.
        End If
        TmpR = TmpR + 1                                     '     Advance to the next row
    Loop                                                    'CHECK AGAIN
       
    'PRECONFIG ENGINEER
    TmpR = SDR                                              'Get the Starting Date Row
    Do While Aws.Cells(TmpR, 1) = DateValue(CurStrDte) And _
             Aws.Cells(TmpR, APCC) <> ""                    'Is the Preconfiguration Eng not blank and does the Starting Date Row match the Starting Date?
        'Cells(TmpR, APCC).Select 'FOR TESTING ONLY
        If EngFreeTrghEndDate(Aws, Aws.Cells(TmpR, APCC), CurStrDte, CurEndDte, TmpR, APCC) Then
            PreconfigurationEngineer.AddItem Aws.Cells(TmpR, APCC) 'YES: Add the Preconfiguration Eng to the list.
        End If
        TmpR = TmpR + 1                                     '     Advance to the next row
    Loop                                                    'CHECK AGAIN

There is a lot more than this but the only things that change are the field names and one variable, the cell's column. These are what I am calling Field Names: LeadEngineer, ImplementationEngineer, PreconfigurationEngineer...

I want to create one loop for all of them but how do I pass the two variables including the Field Names?
 
I cannot thank you enough for your continued support. When I try to set it as a string I still get the same error, Type mismatch with the "a" selected. I have a() dimensioned as a string with this command:

Code:
  Dim a() As String, b() As Variant, i As Integer, cr As Integer
    Set cb = a(i)
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,215,566
Messages
6,125,589
Members
449,237
Latest member
Chase S

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