Jul 21 2023 10:15 AM
Mainly looking for What version of Excel is causing this issue and how to work around it. The VBA code pastes all the devices I need to a column on the "Dropdowns" sheet, then it uses the Sort, Unique, and Filter functions to create the array of devices the dropdowns point to. When I run this on my machine it works 100% of the time, but when this code is ran on my Boss's machine it fails with an error.
Here is the code before (with added comments to help understand my intents, and unincluded variables) :
'not shown variables in this code snippit
'With Worksheets("Structure") which is the sheet the dropdown is for
'NewRow is the row on that structure sheet, PLCtable is the table the info is at
'DropdownStart is the string for the column letter the list of devices is on
'DropdownColumn is the integer for the column the list of devices is on
'The formula is pasted on the column next to the list of devices it refers to
'pastes the ModuleDrop array onto the column DropdownStart to ensure the Device list is created and up to date
Worksheets("Dropdowns").Range(DropdownStart & "3").Resize(UBound(ModuleDrop) + 1).Value = WorksheetFunction.Transpose(ModuleDrop)
'creates the formula to reference the newly updated Device list
'results look like this: =SORT(UNIQUE(FILTER($A$3:$A$1000,$A$3:$A$1000<>"")))
Worksheets("Dropdowns").Cells(3, DropdownColumn + 1).Formula2 = "=SORT(UNIQUE(FILTER($" _
& DropdownStart & "$3:$" & DropdownStart & "$1000,$" & DropdownStart & "$3:$" & DropdownStart & "$1000<>" & Chr(34) & Chr(34) & ")))"
'changes DropdownStart to be the column letter of the formula column
DropdownStart = Split(Worksheets("Dropdowns").Cells(1, DropdownColumn + 1).Address, "$")(1)
'adds the validation to reference the corresponding formula column
.Cells(NewRow, PLCtable.ListColumns("Device").Index).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Formula1:="=Dropdowns!" & "$" & DropdownStart & "$3#"
.Cells(NewRow, PLCtable.ListColumns("Device").Index).Validation.IgnoreBlank = True
This is the "on the fly" workaround I made so the boss can continue to work. The Dropdown luckily isn't crucial, but definitely needs to be there in the future since it's a feature they asked for.
'error handling for something that is only happening on Mark's computer. possibly a version issue
On Error Resume Next
Worksheets("Dropdowns").Cells(3, DropdownColumn + 1).Formula2 = "=SORT(UNIQUE(FILTER($" _
& DropdownStart & "$3:$" & DropdownStart & "$1000,$" & DropdownStart & "$3:$" & DropdownStart & "$1000<>" & Chr(34) & Chr(34) & ")))"
If Err <> 0 Then
Call ErrorMessage(Errors, "Creating Device Dropdown", "I think the formula I'm using is version exclusive to the latest Excel version")
Call ErrorMessage(Errors, "Creating Device Dropdown", "Panel: " + Panel + ", Slot: " + CStr(SlotsArray(Count, 1)) + ", Device: " + CStr(SlotsArray(Count, 2)))
End If
On Error GoTo 0
DropdownStart = Split(Worksheets("Dropdowns").Cells(1, DropdownColumn + 1).Address, "$")(1)
On Error Resume Next
.Cells(NewRow, PLCtable.ListColumns("Device").Index).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Formula1:="=Dropdowns!" & "$" & DropdownStart & "$3#"
.Cells(NewRow, PLCtable.ListColumns("Device").Index).Validation.IgnoreBlank = True
On Error GoTo 0
The ErrorMessage() subroutine is some error handling I have built into this excel. I was using to see if it was the Device referenced or just the dropdown formula in general. It was happening on all Devices I feed it.
Also is there anything else along this line to look out for in the future? Sorry for my suboptimal code, I'm still learning VBA and am an Electrical Engineer by trade. I originally had it just use a string for the dropdown (IE. "Device1,Device2,Device3"), but those fail when they're more then 256 characters and there are too many devices in the dropdowns to fit in that limit.
Note: I would attach the entire Excel if I could, but I'm unsure on the legality since it's technically company property at this point.
Jul 21 2023 02:17 PM
@BlakeBessigner wrote:Mainly looking for What version of Excel is causing this issue and how to work around it. The VBA code pastes all the devices I need to a column on the "Dropdowns" sheet, then it uses the Sort, Unique, and Filter functions to create the array of devices the dropdowns point to. When I run this on my machine it works 100% of the time, but when this code is ran on my Boss's machine it fails with an error.
Try using "Search_deList_v2.1", it's a free Excel add-in, it works on Excel 2007 or later.
Its function is to speed up the search in the data validation list. In any cell that has data validation (with type List) pressing ALT+RIGHT arrow will open a User Form with a combobox. You can type multiple keywords (separated by a space) in the combobox to search items on the list. It also gives you a unique & sorted list.
By using this add-in, you don't need VBA to have this searchable combobox, so you can save your files as .xlsx.
This new version has some additional features, some of them:
Several ways to search, like using AND or OR or LIKE operator , with or without keyword order.
Sort the list by original order or ascending order.
Widen or shorten the combobox width at run time.
Insert multiple entries into the cell.
You can find it here:
Jul 25 2023 11:14 AM
Jul 25 2023 11:16 AM
Jul 25 2023 06:17 PM
Jul 27 2023 04:06 AM
Searching and creating the dropdowns manually via an add-in would add further steps for the user and overcomplicate a process that is intended to be as easy as possible,
The title is somewhat misleading. In reality, the add-in is not for creating data validation; rather, it is designed to automatically generate a searchable combobox based on existing data validation. The list in the combobox is sorted and unique.