Need help creating a form to let user choose columns

ChrisOswald

Active Member
Joined
Jan 19, 2010
Messages
454
Hi,

I need to build a general use userform to let the user select specific columns based on header names. I'm thinking that it would be nifty if I could call the form up using something like this code; However, I suspect that there might be something already available in Excel to do a lot of the grunt work of the form design, but I have no idea of how what that would be.

Note: I'm in no way married to the requirement of using only one form for both optional and required items, using the same form twice (once for required items and once for optional items) would be perfectly fine. A series of input boxes would be clunky and I'd like to avoid that.

Rough draft of calling code:
Code:
    Dim strRequiredHeader() as string
    Dim strOptionalHeader() as string
    Dim FrmColumnSelecter as Form  '? not sure of declaration type, 
            'or if I even need to declare this if it's included in the project
    Dim lngReqHeaderCol() as long
    Dim lngOptHeaderCol() as long
    Dim HR as long
 
    'hard code values in depending on use...
    redim strRequiredHeader(0 to 1)
    strRequiredHeader(0) = "Account Number"
    strRequiredHeader(1) = "Invoice Number"
    redim strOptionalHeader(0 to 1)
    strOptionalHeader(0) = "Purchase Order Number"
    strOptionalHeader(1) = "Check Number Paid On"
 
    FrmColumnSelecter.SheetSource = ActiveSheet
    FrmColumnSelecter.RequiredHeaderNames = strRequiredHeader()
    FrmColumnSelecter.OptionalHeaderNames = strOptionalHeader()
    FrmColumnSelecter.show
 
    'Then some magic happens with the form, 
    'and some new properties are created
 
    'the required headers must be selected: obviously I'll need some way
    'to allow the user to quit out if one is found to be missing.  Otherwise,
    'the array returns which column number of the corresponding
    'header name.
    lngReqHeaderCol() = FrmColumnSelecter.RequiredHeaderColumns
 
    'if one of the optional items isn't matched up by the user,
    'return a value of 0 for the column it's in.
    lngOptHeaderCol() = FrmColumnSelecter.OptionalHeaderColumns
 
    'This is the row number that the header information is found in.
    'I suppose it'd be nice if I could get this to work and allow there to 
    'be no header row, but that should (hopefully) be a uncommon 
    'occurance
    HR = FrmColumnSelecter.HeaderRow
 
    'Now do whatever with this info...
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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