Related
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
I have a slew of rows (100K+) to search and modify the contents.
For example the cells contain similiar text as DGC9610411:DB:10:82
All of this text can change per row except that fact that the : means something to me.
In this and every other row, i need to remove the first : and all the text after so that the cell would look like this DGC9610411
Next I will be adding the contents of another cell to the end. I think that will be an easy step and I could most likely figure that out without much effort.
I have this code in a while loop for each row. so the code is looking at one row at a time.
I have searched but everyone seems to have a different set of needs.
Just use Find and Replace, no need for vba or formulas.
Select the column containing the data that you need to modify
Press Ctrlh to open the Find and Replace dialog.
In the "Find what:" field, type :*
In the "Replace with:" field, leave it blank
Click Replace All
EDIT: If it has to be VBA, this simple macro will accomplish the same thing. Be sure to change the A to your actual column letter.
Sub tgr()
Columns("A").Replace ":*", ""
End Sub
EDIT: Upon request I am adding a formula solution. In cell B1 and copied down:
=LEFT(A1,FIND(":",A1&":")-1)
Try this small macro:
Sub colonoscopy()
Dim c As String
Dim r As Range, I As Long
For Each r In ActiveSheet.UsedRange
v = r.Value
I = InStr(1, v, ":")
If I > 0 Then
r.Value = Mid(v, 1, I - 1)
End If
Next r
End Sub
I'm trying to get rid of the blank cells between my cells which have info in them by using F5 to find the blank cells, then Ctrl + - to delete them, and shift the cells up. But when I try to do that, it tells me that there are 'No cells found'.
I've noticed that if I select my 'blank' cells, Excel still counts them: which is weird. But if I press Delete on those selected cells, the count goes away, and then I can go F5, blanks, Ctrl + - and Shift cells up, and it works...
So my question is how can I still do that, but with these blank cells which Excel thinks aren't blank? I've tried to go through and just press delete over the blank cells, but I have a lot of data and realized that it would take me WAY too long. I need to find a way to select these 'blank' cells within a selection of data.
a simple way to select and clear these blank cells to make them blank:
Press ctrl + a or pre-select your range
Press ctrl + f
Leave find what empty and select match entire cell contents.
Hit find all
Press ctrl + a to select all the empty cells found
Close the find dialog
Press backspace or delete
This worked for me:
CTR-H to bring up the find and replace
leave 'Find What' blank
change 'Replace with' to a unique text, something that you are
positive won't be found in another cell (I used 'xx')
click
'Replace All'
copy the unique text in step 3 to 'Find what'
delete the unique text in 'Replace with'
click 'Replace All'
A revelation: Some blank cells are not actually blank! As I will show cells can have spaces, newlines and true empty:
To find these cells quickly you can do a few things.
The =CODE(A1) formula will return a #VALUE! if the cell is truly empty, otherwise a number will return. This number is the ASCII number used in =CHAR(32).
If you select the cell and click in the formula bar and use the cursor to select all.
Removing these:
If you only have a space in the cells these can be removed easily using:
Press ctrl + h to open find and replace.
Enter one space in the find what, leave replace with empty and ensure you have match entire cell contents is ticked in the options.
Press replace all.
If you have newlines this is more difficult and requires VBA:
Right click on the sheet tab > view code.
Then enter the following code. Remember the Chr(10) is a newline only replace this as required, e.g. " " & Char(10) is a space and a newline:
Sub find_newlines()
With Me.Cells
Set c = .Find(Chr(10), LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = ""
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address <> firstAddress
End If
End With
End Sub
Now run your code pressing F5.
After file supplied: Select the range of interest for improved performance, then run the following:
Sub find_newlines()
With Selection
Set c = .Find("", LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = ""
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address <> firstAddress
End If
End With
End Sub
All, this is pretty simple. I have been trying for the same and this is what worked for me in VBA
Range("A1:R50").Select 'The range you want to remove blanks
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Regards,
Anand Lanka
I had a similar problem where scattered blank cells from an export from another application were still showing up in cell counts.
I managed to clear them by
Selecting the columns/rows I wanted to clean, then doing
"Find" [no text] and "Replace" [word of choice].
Then I did "Find" [word of choice] and "Replace" with [no text].
It got rid of all hidden/phantom characters in those cells. Maybe this will work for you?
If you don't have formatting or formulas you want to keep, you can try saving your file as a tab delimited text file, closing it, and reopening it with excel. This worked for me.
Not sure if this has already been said, but I had a similar problem with cells showing nothing in them, but not being blank when you run the IsBlank() formula.
I selected the entire column, selected Find & Replace, found cells with nothing and replaced with a 0, then ran find and replace again, finding cells with 0 and replacing with "".
This solved my problem and allowed me to search for Blank cells (F5, Special, Blanks) and delete rows that were blank....BOOM.
May not work for every application but this solved my problem.
Sometimes there are spaces in cells which appear blank but if you hit F2 on the cell, you'll see spaces. You can also search this way if you know the exact number of spaces in a cell
The most simple solution for me has been to:
1)Select the Range and copy it (ctrl+c)
2)Create a new text file (anywhere, it will be deleted soon), open the text file and then paste in the excel information (ctrl+v)
3)Now that the information in Excel is in the text file, perform a select all in the text file (ctrl+a), and then copy (ctrl+c)
4)Go to the beginning of the original range in step 1, and paste over that old information from the copy in step 3.
DONE! No more false blanks! (you can now delete the temp text file)
'Select non blank cells
Selection.SpecialCells(xlCellTypeConstants, 23).Select
' REplace tehse blank look like cells to something uniqu
Selection.Replace What:="", Replacement:="TOBEDELETED", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'now replace this uique text to nothing and voila all will disappear
Selection.Replace What:="TOBEDELETED", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Found another way. Set AutoFilter for all columns (important or you will misalign data) by selecting the header row > 'Data' tab > Sort and filter - 'Filter'. Use drop-down in first data column, untick 'Select all' and select only '(Blanks)' option > [OK]. Highlight rows (now all together) > right click > 'Delete row'. Head back to the drop-down > 'Select all'. Presto :)
This works with numbers.
If your range is O8:O20, then in a nearby empty range (e.g. T8:T20) enter =O8/1 and fill down. This will give you a result of #VALUE for the 'empty' cells and your original number will remain as it was.
Then with the range T8:20 selected (CTL-* if it's not already) hit F5 and choose Special. From the Special dialogue, choose Errors and click OK. This will deselect your actual numbers leaving only the #VALUE cells selected. Delete them and you will have actual empty cells. Copy T8:T20 and paste back over O8:O20.
Essentially, since blank cells doesn't work, you need to convert the 'empty' cells into something that the Go To Special can latch on to. Any action that would convert into #VALUE would work, and other 'error' types should be supported as well.
My method is similar to Curt's suggestion above about saving it as a tab-delimited file and re-importing.
It assumes that your data has only values without formulas.
This is probably a good assumption because the problem of "bad" blanks is caused by the confusion between blanks and nulls -- usually in the data imported from some other place -- so there shouldn't be any formulas.
My method is to parse in place -- very similar to saving as a text file and re-importing, but you can do this without closing and re-opening the file.
It's under Data > Text-to-Columns > delimited > remove all parsing characters (can also choose Text if you want) > Finish. This should cause Excel to re-recognize your data from scratch or from text and recognize blanks as really blank.
You can automate this in a subroutine:
Sub F2Enter_new()
Dim rInput As Range
If Selection.Cells.Count > 1 Then Set rInput = Selection
Set rInput = Application.InputBox(Title:="Select", prompt:="input range", _
Default:=rInput.Address, Type:=8)
' Application.EnableEvents = False: Application.ScreenUpdating = False
For Each c In rInput.Columns
c.TextToColumns Destination:=Range(c.Cells(1).Address), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, _
FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Next c
Application.EnableEvents = True: Application.ScreenUpdating = True
End Sub
You can also turn-on that one commented line to make this subroutine run "in the background". For this subroutine, it improves performance only slightly (for others, it can really help a lot).
The name is F2Enter because the original manual method for fixing this "blanks" problem is to make Excel recognize the formula by pushing F2 and Enter.
Here's how I fixed this problem without any coding.
Select the entire column that I wanted to delete the "blank" cells from.
Click the Conditional Formatting tab up top.
Select "New Rule".
Click "Format only cells that contain".
Change "between" to "equal to".
Click the box next to the "equal to" box.
Click one of the problem "blank" cells.
Click the Format Button.
Pick a random color to fill the box with.
Press "OK".
This should change all of the problem "blank" cells to the color that you chose. Now Right click one of the colored cells, and go to "Sort" and "Put selected cell color on top".
This will put all of the problem cells at the top of the column and now all of your other cells will stay in the original order you put them in. You can now select all of the problem cells in one group and click the delete cell button on top to get rid of them.
Goto->Special->blanks does not like merged cells. Try unmerging cells above the range in which you want to select blanks then try again.
I had a similar problem with getting the COUNTA formula to count non-blank cells, it was counting all of them (even the blank one's as non-blank), I tried =CODE() but they had no spaces or new lines.
I found that when I clicked in the cell and then clicked out of it then the formula would count the cell. I had thousands of cells so could not do this manually. I wrote this VBA statement to literally check all the cells and if they were blank then to make them blank. Ignore the pointlessness of this macro and trust me that it actually worked by forcing Excel to recognize the empty cells as actually being empty.
'This checks all the cells in a table so will need to be changed if you're using a range
Sub CreateBlanks()
Dim clientTable As ListObject
Dim selectedCell As Range
Set clientTable = Worksheets("Client Table").ListObjects("ClientTable")
For Each selectedCell In clientTable.DataBodyRange.Cells
If selectedCell = "" Then
selectedCell = ""
End If
Next selectedCell
End Sub
Save your dataset in CSV file and open that file and copy the dataset and paste to the excel file.
and then crtl + g will work on your file, means the excel will recognize that blank is really blank.
I want to build a tab delimited string and insert it in cell "A1". For some reason, it does not identify the tab delimiter. Here is my code:
Worksheets("Sheet1").Range("A1").Value = Join(Application.WorksheetFunction.Transpose(Worksheets("Sheet1").Range("B1:B11")), Chr(9))
I even tried the "vbTab" instead of "Chr(9)" but I still see no tabs in the string. Its inserting a string without any deliminator.
Thanks in advance
The tabs are there but are not being displayed. Try
Dim stg As String
Dim pos As Long
Worksheets("Sheet1").Range("A1").Value = Join(Application.WorksheetFunction. _
transpose(Worksheets("Sheet1").Range("B1:B11")), Chr(9))
stg = Worksheets("Sheet1").Range("A1").Value
For pos = 1 To Len(stg)
Debug.Print Asc(Mid(stg, pos, 1)) & " ";
Next
Debug.Print
The Immediate Window will shows the ASCII values of your strings spearated by nines.
Excel cannot visually display tabs within a cell.
As far as Excel is concerned, tab means to move to the next cell. If you copy a string that has a tab in it and paste the result into Excel, it will put the text before the tab in your selected cell and the text after the tab in the next cell.
If you just need the tab to be there then you can rest assured that it is. If you want it to display visually then modify your question to explain what you are trying to do.
I've got a massive Excel 2003 spreadsheet I'm working on. There are a lot of very large formulas with a lot of cell references. Here's a simple example.
='Sheet'!AC69+'Sheet'!AC52+'Sheet'!AC53)*$D$3+'Sheet'!AC49
Most of them are more complicated than that, but this gives a good idea of what I'm working with. Few of these cell references are absolute ($s). I'd like to be able to copy these cells to a different location without the cell references changing. I know I can simply use f4 to make the references absolute, but there is a lot of data and I may need to use Fill later. Is there any way to temporarily disable the cell reference changing on copy-paste/fill without making the references absolute?
EDIT: I just found out that you can do this with VBA by copying the cell contents as text instead of a formula. I'd like to not have to do this though because I want to copy whole rows/columns at once. Is there a simple solution I am missing?
From http://spreadsheetpage.com/index.php/tip/making_an_exact_copy_of_a_range_of_formulas_take_2:
Put Excel in formula view mode. The easiest way to do this is to press Ctrl+` (that character is a "backwards apostrophe," and is usually on the same key that has the ~ (tilde).
Select the range to copy.
Press Ctrl+C
Start Windows Notepad
Press Ctrl+V to past the copied data into Notepad
In Notepad, press Ctrl+A followed by Ctrl+C to copy the text
Activate Excel and activate the upper left cell where you want to paste the formulas. And, make sure that the sheet you are copying to is in formula view mode.
Press Ctrl+V to paste.
Press Ctrl+` to toggle out of formula view mode.
Note: If the paste operation back to Excel doesn't work correctly, chances are that you've used Excel's Text-to-Columns feature recently, and Excel is trying to be helpful by remembering how you last parsed your data. You need to fire up the Convert Text to Columns Wizard. Choose the Delimited option and click Next. Clear all of the Delimiter option checkmarks except Tab.
Or, from http://spreadsheetpage.com/index.php/tip/making_an_exact_copy_of_a_range_of_formulas/:
If you're a VBA programmer, you can simply execute the following code:
With Sheets("Sheet1")
.Range("A11:D20").Formula = .Range("A1:D10").Formula
End With
A very simple solution is to select the range you wish to copy, then Find and Replace (Ctrl + h), changing = to another symbol that is not used in your formula (e.g. #) - thus stopping it from being an active formula.
Then, copy and paste the selected range to it's new location.
Finally, Find and Replace to change # back to = in both the original and new range, thus restoring both ranges to being formulae again.
I came to this site looking for an easy way to copy without changing cell references. But now I thnk my own workaround is simpler than most of these methods. My method relies on the fact that Copy changes references but Move doesn't. Here's a simple example.
Assume you have raw data in columns A and B, and a formula in C (e.g. C=A+B) and you want the same formula in column F but Copying from C to F leads to F=D+E.
Copy contents of C to any empty temporary column, say R. The relative references will change to R=P+Q but ignore this even if it's flagged as an error.
Go back to C and Move (not Copy) it to F. Formula should be unchanged so F=A+B.
Now go to R and copy it back to C. Relative reference will revert to C=A+B
Delete the temporary formula in R.
Bob's your uncle.
I've done this with a range of cells so I imagine it would work with virtually any level of complexity. You just need an empty area to park the coiped cells. And of course you have to remember where you left them.
This simple trick works: Copy and Paste. Do NOT cut and paste. After you paste, then reselect the part you copied and go to EDIT, slide down to CLEAR, and CLEAR CONTENTS.
Simple workaround I used just now while in a similar situation:
Make a duplicate of the worksheet.
Cut + Paste the cells with formulas from the duplicate worksheet (e.g. Copy of Sheet1) into the original worksheet.
Remove all occurrences of the the duplicate sheet's name from the newly pasted formulas; e.g. find-and-replace all occurrences of the search term 'Copy of Sheet1'! with an empty string (i.e. blank).
Delete duplicate worksheet to clean up.
Note: if your sheet name lacks spaces you won't need to use the single quote/apostrophe (').
Your cell references are now copied without being altered.
I think that you're stuck with the workaround you mentioned in your edit.
I would start by converting every formula on the sheet to text roughly like this:
Dim r As Range
For Each r In Worksheets("Sheet1").UsedRange
If (Left$(r.Formula, 1) = "=") Then
r.Formula = "'ZZZ" & r.Formula
End If
Next r
where the 'ZZZ uses the ' to signify a text value and the ZZZ as a value that we can look for when we want to convert the text back to being a formula. Obviously if any of your cells actually start with the text ZZZ then change the ZZZ value in the VBA macro to something else
When the re-arranging is complete, I would then convert the text back to a formula like this:
For Each r In Worksheets("Sheet1").UsedRange
If (Left$(r.Formula, 3) = "ZZZ") Then
r.Formula = Mid$(r.Formula, 4)
End If
Next r
One real downside to this method is that you can't see the results of any formula while you are re-arranging. You may find that when you convert back from text to formula that you have a slew of #REF errors for example.
It might be beneficial to work on this in stages and convert back to formulas every so often to check that no catastrophes have occurred
It's common to use find/ replace to disable formulas whilst performing manipulations. For example, copy with transpose. The formula is disabled by placing some placeholder (e.g. "$=") in front of it. Find replace can get rid of these once the manipulation is complete.
This vba just automates the find/ replace for the active sheet.
' toggle forumlas on active sheet as active/ inactive
' by use of "$=" prefix
Sub toggle_active_formulas()
Dim current_calc_method As String
initial_calc_method = Application.Calculation
Application.Calculation = xlCalculationManual
Dim predominant As Integer
Dim c As Range
For Each c In ActiveSheet.UsedRange.Cells
If c.HasFormula Then
predominant = predominant + 1
ElseIf "$=" = Left(c.Value, 2) Then
predominant = predominant - 1
End If
Next c
If predominant > 0 Then
For Each c In ActiveSheet.UsedRange.Cells
On Error Resume Next
If c.HasFormula Then
c.Value = "$" & c.Formula
End If
Next c
Else
For Each c In ActiveSheet.UsedRange.Cells
On Error Resume Next
If "$=" = Left(c.Value, 2) Then
c.Formula = Right(c.Value, Len(c.Value) - 1)
End If
Next c
End If
Application.Calculation = initial_calc_method
End Sub
This macro does the whole job.
Sub Absolute_Reference_Copy_Paste()
'By changing "=" in formulas to "#" the content is no longer seen as a formula.
' C+S+e (my keyboard shortcut)
Dim Dummy As Range
Dim FirstSelection As Range
Dim SecondSelection As Range
Dim SheetFirst As Worksheet
Dim SheetSecond As Worksheet
On Error GoTo Whoa
Application.EnableEvents = False
' Set starting selection variable.
Set FirstSelection = Selection
Set SheetFirst = FirstSelection.Worksheet
' Reset the Find function so the scope of the search area is the current worksheet.
Set Dummy = Worksheets(1).Range("A1:A1").Find("Dummy", LookIn:=xlValues)
' Change "=" to "#" in selection.
Selection.Replace What:="=", Replacement:="#", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Select the area you want to paste the formulas; must be same size as original
selection and outside of the original selection.
Set SecondSelection = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
Set SheetSecond = SecondSelection.Worksheet
' Copy the original selection and paste it into the newly selected area. The active
selection remains FirstSelection.
FirstSelection.Copy SecondSelection
' Restore "=" in FirstSelection.
Selection.Replace What:="#", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Select SecondSelection.
SheetSecond.Activate
SecondSelection.Select
' Restore "=" in SecondSelection.
Selection.Replace What:="#", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' Return active selection to the original area: FirstSelection.
SheetFirst.Activate
FirstSelection.Select
Application.EnableEvents = True
Exit Sub
Whoa:
' If something goes wrong after "=" has been changed in FirstSelection, restore "=".
FirstSelection.Select
Selection.Replace What:="#", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
Note that you must match the size and shape of the original selection when you make your new selection.
I found this solution which automates #Alistair Collins solution.
Basically you will change the = in any formula to * then do the paste after that you will change it back
Dim cell As Range
msgResult = MsgBox("Yes to lock" & vbNewLine & "No unlock ", vbYesNoCancel + vbQuestion, "Forumula locker")
If msgResult = vbNo Then
For Each cell In Range("A1:i155")
If InStr(1, cell.Value, "*") > 0 Then
cell.Formula = Replace(cell.Formula, "*", "=")
End If
Next cell
ElseIf msgResult = vbYes Then
For Each cell In Range("A1:i155")
If cell.HasFormula = True Then
cell.Formula = Replace(cell.Formula, "=", "*")
End If
Next cell
End If
Try this:
Left-click the tab, making a copy of the whole sheet, then cut the cells you want to keep the same and paste them into your original worksheet.
I found another workaround that is very simple:
1. Cut the contents
2. Paste them in the new location
3. Copy the contents that you just pasted into the new location you want.
4. Undo the Cut-Paste operation, putting the original contents back where you got them.
5. Paste the contents from the clipboard to the same location. These contents will have the original references.
It looks like a lot, but is super fast with keyboard shortcuts:
1. Ctrl-x, 2. Ctrl-v, 3. Ctrl-c, 4. Ctrl-z, 5. Ctrl-v
Haven't check in Excel, but this works in Libreoffice4:
The whole thing of address rewriting comes during consecutive
(a1) cut
(a2) paste
You need to interrupt the consecutiveness by putting something in-between:
(b1) cut
(b2) select some empty cells (more than 1) and drag(move) them
(b3) paste
Step (b2) is where the cell that is about to update itself stops the tracking. Quick and simple.
Click on the cell you want to copy. In the formula bar, highlight the formula.
Press Ctrl C.
Press escape (to take you out of actively editing that formula).
Choose new cell. Ctrl V.