简体   繁体   中英

Comma Separator: Ignore the comma within the data using excel macro

I'm new in using of excel macro vba and I have a problem with listing the data in dropdown. I want to create a dropdown and has a comma in one line of record, but my code separates it. Here's my code.

Code:

Dim ShipAddress As String
Dim MyList5() As String
ReDim MyList5(ShipAddressCount)

For h = 1 To ShipAddressCount
    ShipAddress = rsShipAddress!ShippingAddress
    MyList5(h) = ShipAddress
    rsShipAddress.MoveNext
Next


 With Range("E4:E" + cnt).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=Join(MyList5, ",")
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With

When the list has a dropdown record of "name,name" it would count as two lines. I want to have a record in list that has a comma in one line. Do you all have other way to resolve this?

Any help will be appreciated. Thank you.

You can put your values into a column of cells, set it up as a Named Range (I usually start these with "DrpDwn_" to show that they are Drop-Down lists) and then use that point your list at the Named Range.

eg if your Named Range was "DrpDwn_Shipping" then you would use Formula1:="=DrpDwn_Shipping"

The issue with this approach is, of course, that you need a column & a Named Range for every distinct drop-down, ideally on a very hidden worksheet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM