My VBA excell application needs to read non-latin cell values:
someString = Cells(1,1).value
when I analyse the hex content of someString, it contains only a sequence of "3F", i.e. question marks.
I need to obtain the original unicode string. When I copy the non-latin cell value into ultra-edit then the information is correctly copied
Found the solution here
au crypto website has vba code that does the job
Related
VBA Masters,
I have a merged range in Excel (A1:D7) that has a varying number of lines of text. Each new line of text starts with a "*" to denote the beginning of a new statement.
I need to be able to store each of those statements in a variable and write them out to their own individual cells rather than having it in the merged cell area.
I've attached an image of an example of the block of text.
I'm trying to get formatted data from an excel cell. This cell can contains special symbols like &,',",<,>, LF (End of Line). All this text content will be set inside of a xml structure. For this reason I have to get all this text and parse all special symbols and transformed to a character entity
(& ' " <....)
To do this, first I have to load the data from cell in my code, it looks like:
Set beforeTransformation = Sheets(langId).Range("A46").Text
As official documentation says:
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-text-property-excel
It's a read only property, so when I execute the VBA macro, next error is outputted,
Compile error: Object required
The question is, which is the best way to get data from a cell and set it into a variable for future transformation?
Thank you.
As shown in the image above, I need to get the values following a pattern like for example TK AK15590 (TK AK followed by a series of numbers as shown) into cell B2. The same with the rest of the cells in the description column using vba macro in excel. Appreciate if anyone could give me a sample vba code or some information on how I could do this.
VBA is not requiered here. You should use formulas that manipulate text. In this particular case, the following would work:
=IFERROR(MID(A2,FIND("TK AK",A2),FIND(" ",A2,FIND("TK AK",A2)+4)-FIND("TK AK",A2)), "ERROR MESSAGE HERE")
When the length of the string you want to extract is fixed (10 in this case), you could simply use this:
=IFERROR(MID(A2,FIND("TK AK",A2),10), "ERROR MESSAGE HERE")
I have a peculiar problem with hidden characters in an Excel spreadsheet which uses VBA to create a text file. I've attached a link to a test version of the file, and I'll explain as best I can the issue.
The file creates a plain txt file that can be used to feed data into a System we use. It works well normally, however we've been supplied approximately 15,000 rows of data, and at random points throughout there are hidden characters.
In the test file, there's 1 row and it's cell B11 that has hidden characters at the beginning and end of the value. If you put your cursor at the end of it, and press the backspace key, it will look as if nothing has happened, but actually you've just deleted one of the characters.
As far as Excel is concerned, those hidden characters are question marks, but they're not, as text stream would parse those, but it doesn't, and instead throws up an invalid procedure call error.
I've tried using Excel's CLEAN formula, I've tried the VBA equivalent, tried using 'Replace', but nothing seems to recognise those characters. Excel is convinced they're just question marks, even an ASCII character call gives me the same answer (63), but replace doesn't replace them as question marks, it just omits them!
Any help on this, even if it's just a formula I could apply would be appreciated. In the interests of data protection the data in the file is fake by the way, it's nobody's real NI number.
The excel file with vba code is here
This VBA macro could be run on its own or in conjunction with the ClearFormatting macro. It did strip out the rogue unichars from the sample.
Sub strip_Rogue_Unichars()
Dim uc As Long
With Cells(11, 1).CurrentRegion
For uc = 8000 To 8390
.Replace what:=ChrW(uc), replacement:=vbNullString, lookat:=xlPart
DoEvents
Next uc
End With
End Sub
There's probably a better way to do this and being able to restrict the scope of the Unicode characters to search and replace would obviously speed things up. Turning off .EnableEvents, .ScreenUpdating, etc would likewise help. I believe the calculation was already at manual. I intentionally left a DoEvents in the loop as my first run was several thousand different unichars.
I have to read the text from the cells of a column in excel and search for it in another sheet.
say for example, the text in sheet1 column A is "Evoked Potential Amplitude N2 - P2." This has to be searched in sheet2 column C. This fails because a question mark appears before the "E" which is not present in the value in the sheet2.
Both are representation of same character in different application. Maybe someone might recognize it.
In the excel sheet I don't see any junk characters, but while handling it in the vb code I see a question mark before the word - Evoke.
This data was extracted from a share point application and this character (?) is not visible to the plain eye. Search and replace functions are not working in this case.
Unicode 8203 is a zero-width space. I'm not sure where it's coming from. It is probably a flaw in the way the data is imported into Excel which you haven't noticed before, but it might be worth fixing.
In the meantime, you can simply use the Mid() function in Excel VBA to remove the unwanted character. For example instead of
x = cells(1,1).value
use
x = Mid(cells(1,1).value,2)
which deletes the first character.