I would like to insert data from three different drop downs into my spreadsheet but I am having several difficulties. There are three drop downs called cbo_fac1, cbo_fac2 and cbo_fac3.
Here are the use cases:
Use case 1 – Results in No preference being inserted into spreadsheet
cbo_fac1 - No preference
cbo_fac2 - No preference
cbo_fac3 - No preference
Use case 2a – Results in value, , being inserted into spreadsheet. Should just be value
cbo_fac1 - Value
cbo_fac2 - No preference
cbo_fac3 - No preference
Use case 2b – Results in , value, being inserted into spreadsheet. Should just be value
cbo_fac1 - No preference
cbo_fac2 - Value
cbo_fac3 - No preference
Use case 2c – Results in , , value being inserted into spreadsheet. Should just be value
cbo_fac1 - No preference
cbo_fac2 - No preference
cbo_fac3 - Value
Use case 3a – Results in value, value, being inserted into spreadsheet. Should just be value, value
cbo_fac1 - Value
cbo_fac2 - Value
cbo_fac3 - No preference
Use case 3b – Results in , value, value being inserted into spreadsheet. Should just be value, value
cbo_fac1 - No preference
cbo_fac2 - Value
cbo_fac3 - Value
Use case 3c – Results in value, , value being inserted into spreadsheet. Should just be value, value
cbo_fac1 - Value
cbo_fac2 - No preference
cbo_fac3 - Value
How do I remove the extra commas in Use cases 2a-3c?
Here is my code so far:
If Me.cbo_fac1 <> "No preference" Then
cbo_fac1Entry = Me.cbo_fac1.Value
Else
cbo_fac1Entry = ""
End If
If Me.cbo_fac2 <> "No preference" Then
cbo_fac2Entry = Me.cbo_fac2.Value
Else
cbo_fac2Entry = ""
End If
If Me.cbo_fac3 <> "No preference" Then
cbo_fac3Entry = Me.cbo_fac3.Value
Else
cbo_fac3Entry = ""
End If
cbo_facEntry = cbo_fac1Entry & ", " & cbo_fac2Entry & ", " & cbo_fac3Entry
If cbo_facEntry = " , ," Then
cbo_facEntry = "No preference"
Else
End If
rng1.Offset(1, 15) = cbo_facEntry
I’ve tried inserting this code:
if right(cbo_facEntry,1)="," then
cbo_facEntry= left(len(cbo_facEntry)-1)
end if
if left(cbo_facEntry,1)="," then
cbo_facEntry= right(len(cbo_facEntry)-1)
end if
After:
If cbo_facEntry = ",," Then
cbo_facEntry = "No Preference"
Else
End If
But it doesn’t make much difference, as it doesn’t fulfil the requirements of all the use cases and also returns an invalid syntax error message.
Thanks in advance!
You can add these three lines to your code instead of what you’ve tried: