Assign Chinese character formula to string variable

donfaison

New Member
Joined
Jan 7, 2014
Messages
21
Office Version
  1. 365
Platform
  1. Windows
I have a table I download weekly of over 200 chinese products, to sort and pick out the dozen values I actually need, I filter the table using the chinese name, then copy and paste to another spreadsheet. This was easy when there were only three but now I'm looking for a way to be able to do this automatically from a list of the chinese characters. An example: gasoline is 汽油, but to sort the table, I have to use an assigned string variable using a formula.

Dim CC as string
CC = ChrW(27773) & ChrW(27833)
ActiveSheet.Range("$A$1:$K$225").AutoFilter Field:=1, Criteria1:=CC

This works to find 汽油. Actually assigning CC directly to the cell containing the Chinese text (CC = Sheets("List").Range("A1").value or CC = Sheets("List").Range("A1").text both return CC = "??")

I would like to be able to reassign the CC variable for each item (as they change on occasion) rather than have separate variables for each item as I now have to, causing me to copy sections of code over anytime I introduce a new variable or change the values for some that I have.

The calculations to convert the Chinese characters into the ChrW(#'s) involves first splitting the Chinese name, looking up an AscW() value for each character, then combining them back into a text formula,
Cell X123's formula is ="ChrW("&B123&") & ChrW("&C123&")"
I've tried assigning CC directly,
CC = Sheets("List").Range("X123").value
However CC then = "ChrW(27773) & ChrW(27833)" (with quotes).

Any suggestions?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi

I don't really understand.
If I have the filter value in a cell I can just refer to it.

For ex., if I have the table in A:B and I write the value that you posted in E1, this code works for me:

VBA Code:
Sub Test()
Dim r As Range

Set r = Range("A1").CurrentRegion

r.AutoFilter field:=1, Criteria1:=Range("E1").Value
End Sub

I tried with this data

Book1
ABCDEF
1F1F2Filter by汽油
2汽油s
3y
4n
5汽油y
6n
7n
8
Sheet2



and got the result I expected:


Book1
ABCDEF
1F1F2Filter by汽油
2汽油s
5汽油y
8
Sheet2
 
Upvote 0
I wonder why you use the formula ="ChrW("&B123&") & ChrW("&C123&")". I mean why you enclose the formula with double quotation marks? What if you remove them, using just =ChrW("&B123&") & ChrW("&C123&") ?
 
Upvote 0
Hi

I don't really understand.
If I have the filter value in a cell I can just refer to it.

For ex., if I have the table in A:B and I write the value that you posted in E1, this code works for me:

VBA Code:
Sub Test()
Dim r As Range

Set r = Range("A1").CurrentRegion

r.AutoFilter field:=1, Criteria1:=Range("E1").Value
End Sub

I tried with this data

<deleted> I need to assign the chinese word to a variable, and assigning the cell's value does not work
 
Upvote 0
I wonder why you use the formula ="ChrW("&B123&") & ChrW("&C123&")". I mean why you enclose the formula with double quotation marks? What if you remove them, using just =ChrW("&B123&") & ChrW("&C123&") ?
did you actually manage this? the above "ChrW("&B123&") & ChrW("&C123&")" results in
ChrW(27773) & Chrw(27833)
which, when assigned to a variable in VBA= 汽油 . Trying it without the quotes results in #NAME? for me.
 
Upvote 0
This works to find 汽油. Actually assigning CC directly to the cell containing the Chinese text (CC = Sheets("List").Range("A1").value or CC = Sheets("List").Range("A1").text both return CC = "??")
When you said both return "??", where did you see the question marks? In the watch window/immediate window? If so, you need to set your language in Windows. Check out this thread:

 
Upvote 0
Is something like this what you are after?
 

Attachments

  • test3.jpg
    test3.jpg
    33.6 KB · Views: 26
Upvote 0
Is something like this what you are after?
yes, BUT I am downloading a *.csv file and putting it into Excel. Although what you recommend works, 1) sometimes the names change and I would not find the string. That's why I would like to use a changeable list. 2) if I copy the Chinese from the excel cell, and paste in VBA, the pasted result is "??". [str = Range("A5").value or .text, msgbox str ==> "??"] Those are the reasons why I am deconstructing the Chinese characters and then reconstructing them. I only have a few Chinese-related excel files and I don't read Chinese, so I am keeping my language as English.
 
Upvote 0
yes, BUT I am downloading a *.csv file and putting it into Excel. Although what you recommend works, 1) sometimes the names change and I would not find the string. That's why I would like to use a changeable list. 2) if I copy the Chinese from the excel cell, and paste in VBA, the pasted result is "??". [str = Range("A5").value or .text, msgbox str ==> "??"]
If you add Chinese to Windows, this will not happen. Chinese characters will show up correctly.

Those are the reasons why I am deconstructing the Chinese characters and then reconstructing them. I only have a few Chinese-related excel files and I don't read Chinese, so I am keeping my language as English.
The method I described in the link ADDs a language. It doesn't replace the default language. You can have two or more languages. In other words, you can have English as your default language and Chinese as a secondary language. Both can be displayed properly in VBA. There is no downside I can see.
 

Attachments

  • test4.jpg
    test4.jpg
    23 KB · Views: 17
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top