Hello,
I have a code that replaces text with a number and it works except when a word is contained in another string. For instance, there is "Hispanic" which is a code 3 but since Hispanic also shows up in the string "Two or more Races(Not Hispanic)" which should be 7, I get "Two or more races (Not 3 or Latino)" or if it was "Hispanic/Latino" I would get "3/Latino".
Is there a way to make the text exact in the Const Ethnicity As String statement so that it looks for the entire string between the commas?
I have a code that replaces text with a number and it works except when a word is contained in another string. For instance, there is "Hispanic" which is a code 3 but since Hispanic also shows up in the string "Two or more Races(Not Hispanic)" which should be 7, I get "Two or more races (Not 3 or Latino)" or if it was "Hispanic/Latino" I would get "3/Latino".
Is there a way to make the text exact in the Const Ethnicity As String statement so that it looks for the entire string between the commas?
VBA Code:
Sub Ethnic_Codes(control As IRibbonControl)
'v2.1
Const Ethnicity As String = _
"White,Black or African American,Hispanic,Asian,American Indian or Alaska Native,Native Hawaiian or Other Pacific Islander," & _
"Two or more races(Not Hispanic or Latino),Hispanic/Latino,Black/African American"
Const EthnicCodes As String = _
"1,2,3,4,5,6,7,3,2"
Dim vecEthnicity As Variant
Dim vecEthnicCodes As Variant
Dim rStart As Range
Set rStart = Selection
vecEthnicity = Split(Ethnicity, ",")
vecEthnicCodes = Split(EthnicCodes, ",")
For i = LBound(vecEthnicity) To UBound(vecEthnicity)
'Set the range to suit
rStart.Replace vecEthnicity(i), vecEthnicCodes(i)
Next
End Sub