I am working with arabic and latin characters in an Excel files. I wonder how to find special character like LEFT-TO-RIGHT mark (U+202A) in Microsoft Excel.
I dind't find a way to do that. Only have the oportunity to find especial characters going to a Hexadecimal program and try to find the hex char.
Thanks
Go to Insert -> Symbol.
You'll get a window practically identical to the windows character map. You can even search by character code if you want, find the relevant supported font and type 202A into the "Character Code" box.
This will pick up any ASCII characters in selected range and write it in the cell next to it:
Sub Button1_Click()
Dim cell As Range
For Each cell In Selection
'Find cells with special chars
specialChars = False
For i = 1 To Len(cell.Value)
If (Asc(Mid(cell, i, 1)) >= 128) Then
specialChars = True
End If
Next
'Where to copy cell
If (specialChars = True) Then
cell.Offset(0, 1).Value = cell.Value
End If
Next cell
End Sub
Related
I use a vba script to open another workbook. This workbook is in format .XLS and the content from a DB was stored like:
"Name1" "0" "7,98"
"Name2" "5" "1"
"Name3" "2" "7,1"
When opening the workbook with a VBA script, every cell that includes a comma, is interpreted as text and shows this warning:
The number in this cell is formatted as text or is preceded by an apostrophe
Strangely, if I open the file by double clicking, the numbers are just formatted as text and don't show any error. I guess, Excel is doing some interpretting, which doesn't work.
My code is:
Dim WorkBookImport As Workbook
Name = Application.GetOpenFilename()
If Name <> False Then
Set WorkBookImport = Workbooks.Open(Filename:=Name)
End If
I tried everything from:
Range(mycolumn).Value = Range(mycolumn).Value
For loop with CDbl(.Value)
Range(mycolumn).TextToColumns ...
Nothing works ;( Please help!
Option Explicit
Sub edksg()
Dim c As Range
Set c = Sheet1.Range("D3")
c.Value2 = CDbl(c.Value2)
End Sub
Works fine for me when cell D3 of the worksheet is formatted as text.
Of course, my location uses the comma as decimal separator, so if your location uses a different standard, the issue might be there. In that case, doing something like CDbl(Replace(c.Value2, ",", Application.DecimalSeparator, 1, -1, vbBinaryCompare)) might solve that part of the issue.
If you want to loop through the entirety of some column, the end result might look something like this, assuming the values you want to convert to numbers are in column C.
Option Explicit
Sub edksg()
Dim c As Range
Dim r As Range
Set r = Sheet1.Range("C1:C" & Sheet1.Range("C" & Sheet1.Rows.Count).End(xlUp).Row)
For Each c In r
If Len(c) > 0 Then
c.Value2 = CDbl(Replace(c.Value2, ",", Application.DecimalSeparator, 1, -1, vbBinaryCompare))
End If
Next c
End Sub
It´s a problem with the formating of the cells. You should use NumberFormat to change it.
Sub FormatNumber()
ThisWorkbook.Worksheets("YourWorkbook").Range("YourRange") = CDbl(ThisWorkbook.Worksheets("YourWorkbook").Range("YourRange"))
ThisWorkbook.Worksheets("YourWorkbook").Range("YourRange").NumberFormat = "General"
End Sub
With NumberFormat you can also change it to text if you have the opposite problem, in this case you would use NumberFormat = "#"
How to remove first "=" in all excell cells. There are cells where phone number has this character. Example: =1234/567 and this phone number will be calculated.
Edit: =1234/567 must be converted to 1234/567
Edit: To clear things abc=123 must not be changed, because = is in a middle of word.
I assume you are referring to the '=' sign in formulas. If Excel had regex replacements, you could do this (Word does), but I don't think it does.
How about a quick VBA solution?
Sub RemoveLeadingEquals()
Dim r As Range
For Each r In ActiveSheet.UsedRange
If Left(r.Formula, 1) = "=" Then
r.NumberFormat = "#" ' This *might* not be necessary
r.Formula = Mid(r.Formula, 2)
End If
Next r
End Sub
Check if the forced text formatting (commented above) is necessary. It won't hurt.
Select all cells contain your numbers
Press CTRL+H
Fill "Find What" input box with "="
Just left blank the "Replace with" input box
click "Replace All".
this is so simple you want to remove just = sign
so
press CTRL+f
enter =
Replace with nothing
that's it
As output I have for Range("H" & temp).Cells :
234
0
(Empty)
2
I want to convert it into long or int, because it's a text value. So I did
Range("H" & temp).Cells = CInt(Range("H" & temp).Cells)
It works perfectly for 234, 0 and 2 but when the cell is empty it shows me error. What should I do? I want the empty cell to be taken as 0, of course using VBA macro.
That cell isn't really empty. It has a space or some other non-printing character in it. Try using Trim before using CInt to get rid of the spaces.
If you need to do this in formula, you can use this:
IF(IFERROR(VALUE(A1)); 0; A1)
Enter the number 1 in an unused cell and copy that cell to the clipboard. Highlight the range of cells in which you want blanks replaced by zeros. Choose Edit | Paste Special from the menu. In the Operation section of the resulting dialog box, select the Multiply option and click on OK.You have just multiplied every cell in the range by 1. Numeric cells won't change. Cells containing text data will be ignored. But any cell that was blank will now contain a zero. You could, of course, accomplish the same thing by copying a cell containing 0 to the clipboard and using Add rather than Multiply in the Paste Special dialog.
Sub t()
Dim colNum As Long
colNum = Range("H1").Column 'please coustomize which column
For i = 1 To 4 'Please customize the row range
Cells(i, colNum).Value = CLng(Cells(i, colNum).Value) 'blank --> 0
Cells(i, colNum).NumberFormat = "0.00" 'also changes the numberFormat
Next i
End Sub
This is what worked for me, a custom function, you can change variant to int or double depending on your needs
Function checkEmpty(value As Variant) As Variant
If value = "" Then
checkEmpty = 0
Else
checkEmpty = value
End If
End Function
how to call it:
checkEmpty(cells(1,1).value)
I'm using VBA to do some further formatting to a generated CSV file that's always in the same format. I have a problem with my For Each Loop. the loop deletes an entire row if there is more than one blank row which can be determined from the first column alone.
Dim rowCount As Integer
For Each cell In Columns("A").Cells
rowCount = rowCount + 1
'
' Delete blank row
'
If cell = "" And cell.Offset(1, 0) = "" Then
Rows(rowCount + 1).EntireRow.Delete
spaceCount = 0
End If
Next
At some point the value in the loop one of the calls does not have a value of "", it's just empty and causes it to crash. To solve this I think that changing the type of the cell to text before that compare would work but I can't figure out how (no intellisense!!!)
So how do you convert a cell type in VBA or how else would I solve the problem?
Thanks.
Use cell.Value instead of the cell.Text as it will evaluate the value of the cell regardless of the formating. Press F1 over .Value and .Text to read more about both.
Be carefull with the statement For Each cell In Columns("A").Cells as you will test every row in the sheet (over a million in Excel 2010) and it could make Excel to crash.
Edit:
Consider also the funcion TRIM. It removes every empty space before and after a string. If in the cell there is a white space " "; it will look like empty for the human eye, but it has a space inside therefore is different than "". If you want to treat it like an empty cell, then try:
If Trim(cell.value) = "" then
As #andy (https://stackoverflow.com/users/1248931/andy-holaday) said in a comment, For Each is definitely the way to go. This even allows for there to be spaces in between lines.
Example code:
Sub ListFirstCol()
Worksheets("Sheet1").Activate
Range("A1").Activate
For Each cell In Application.Intersect(Range("A:A"), Worksheets("Sheet1").UsedRange)
MsgBox (cell)
Next
End Sub
Thanks Andy!
I'm currenlty putting together an If, ElseIf and Else statement to go through the lists and make it standard. The parts where I'm struggling are those cells where a superscript character has been used at the end of the sentaence for footnote references. These cells need to be given specific line heights different from the standard 10.5.
Thank you marg for the working If, ElseIf, Else statement.
But how can I find & treat those cells with a superscript character at the end (it's always at the end?
Any guidance or pointers very welcome.
The code below does not update cells with superscript only at the end of the sentence.
Dim targetCell As Range
...
ElseIf targetCell.font.superscript Then
targetCell.RowHeight = 12.75
...
etc
Many thanks
Mike.
This should do it.
Sub testForSuperscriptAtEndOfCellValue()
Dim c As Range
For Each c In Range("A:A").Cells
If c.Characters(Len(c), 1).Font.Superscript Then
c.EntireRow.RowHeight = 42
End If
Next c
End Sub