how to remove space between letters in EXCEL? - excel

I have few numeric columns which I got from a website and copied directly into Excel.
In those columns there is a SINGLE Leading space at the beginning of each number in the cell of the entire column.
try provide vba or any excel formula

This should work.
Sub RemoveSpaces()
Selection.Replace " ", ""
End Sub

Did you try using the Trim() worksheet function?

Related

How can I remove the currency symbol from values in selected cells?

I export Excel files from a website. The exported files have number values with a currency sign before them in a number of columns although the number format of the cells is "General".
I want to remove the currency sign.
Another tricky thing is the headers of these columns and even the column indexes are not constant.
Is there a way to select the cells/columns and remove the currency sign that can work on any Excel file I am working on? Is there an easier solution?
Example of the problem:
try
Range("K2:M6").Replace What:="$", Replacement:=""
or if your prefer selection before:
Selection.Replace What:="$", Replacement:=""
(it's just as quick by hand: just press ctrl+h)
Sub RemoveDollarSigns()
Dim cell As Range
For Each cell in Selection
cell.Value = val(replace(replace(cell.Value, "$", ""), ",", "")
Next cell
End Sub

Show number without exponential expression after remove non-numeric character

I have the following code to remove some "garbage" from cell contents.
Sub RemoveChar()
With Cells
Cells.NumberFormat = "#" ' setting format as text
Cells.Replace What:="#", Replacement:=""
End With
End Sub
The sheet contains values like #123451234512345 and when I remove the # the value changes to look like this 1.23451E+14 even when above I changed the format to text before the replacement.
How can I remove the character # and after remove it say to Excel to show the value as 123451234512345 and not as 1.23451E+14?
Thank in advance.
Try this : (Change 'ActiveCell' to your needs)
ActiveCell.NumberFormat = "0"

eXcel formula for all column value in one cell separating by ","

Look at the column A contain value like the below image . I want a formula to do that .
I don't want to solution like
=CONCATENATE(A1,",",A2,",",A3,",",A4,",",A5)
Excel 2016 has a new function called TextJoin() with the syntax
=TextJoin(delimiter, ignore empty cells, range)
With this, you can use the formula
=TEXTJOIN(",",TRUE,A1:A5)
Edit after comment: It's a new formula in Excel 2016. It does not exist in 2010.
But there are many User Defined Functions (UDF) macros that do a better job than Concatenate, and that can be used in Excel 2010. For example in this post by Jon Acampora. You will need to use the VBA code in each of the spreadsheets where you want to use that special function, though, and all these spreadsheets need to be macro-enabled sheets for these special functions to work.
try this
=A1&","&A2&","&A3&","&A4
OR create custom VBA function
Public Function Join(rng As Range, delimiter As String) As String
Dim cell As Range
For Each cell In rng
Join = Join & cell.Text & delimiter
Next cell
' remove the last delimiter
Join = Left(Join, Len(Join) - Len(delimiter))
End Function
For a long list a more complex formula but one that 'auto adjusts' on copy down might suit:
=IF(A2="",LEFT(B1&A2&",",LEN(B1&A2&",")-2),B1&A2&",")
Assumes a row is inserted at the top with B1 blank. The output would be in ColumnB of the row with the first blank cell in ColumnA after Row1.

#NAME? How to read a formula bar to change the formula of an error - NOT overwritting it

I've been stuck on this problem for a very long time. I've come up with ways around it but each one is bringing more problems to the table.
My macro copys and pastes info from Microsoft Word into Excel and then formats the excel sheet.
Some of the cells however show a #NAME? error. The reason for this is that the cell copies in " =------- List SC". I need to get into this cell and remove the "=------" and leave only the string List SC.
I cannot just over ride it however because each time it changes. It might be "List FL" or "List BP" or any other variation.
I cannot do an InStr or any other function because the VBA code only reads it as an error and doesn't read the formula bar. It only reads "#NAME?" or recognizes an error.
Does anyone have suggestions as to what I can do?
I have included a picture of the issue. The highlights are the error and formula bar.
Thank you!
Jonathan
My macro copys and pastes info from Microsoft Word into Excel...Some of the cells however show a #NAME? error.
You must edit the string you get from Word before you paste it into Excel. You must remove all invalid characters from the string. Then you can paste it as a formula.
If ----List is the value you want in the cell, then precede it with a single quote: '----List so it will be interpreted as text.
In VBA, use the .Formula method to access the actual formula used and do the string replace on it.
With Cells(1,3)
.Formula = Replace(.Formula, "=------ ", "")
End With
So it turns out that I can store the formula into a string and add an " ' " as the first character in the string. I can then replace the existing formula in the cell with the string (below called stfF).
This is my code.
Dim strF As String
For x = 4 To 100
strF = "'" & Cells(x, 1).Formula
Cells(x, 1) = strF
Next

Inserting value into Excel cell instead of formula

I have a VBA script that inserts long strings into Excel cells. In some cases, the string begins with a =. It seems like Excel interprets this as a formula and I get an Out of Memory error due to the memory limitations of formulas.
How do I tell Excel that I am writing a value, not a formula? Currently, I am doing this:
ws.Range("A" & row) = Mid(xml, first, CHUNK_SIZE)
I have tried the following code, but it doesn't work...
ws.Range(...).Value = ....
Append a ' before the = sign:
Sub Test()
'This returns 30 in cell Al
Range("A1").Value = "=SUM(10,10,10)"
'This shows formula as text in cell A2
Range("A2").Value = "'" & "=SUM(10,10,10)"
End Sub
Add an apostrophe ' to the beginning of the string (that excel thinks is a formula) and excel should interpret it as a string instead of a formula.

Resources