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:
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...