I am in trouble. I have thousands of customer data having name, address, zip. I have data in excel and the problem is in zip code. The Zip should be 5 character long and if it is not, we have to add zero at front to make equal to five character. Since there are thousands of data and it is not feasible to change it one by one, can somebody suggest me to format the column of zip so that it could be 5 character long.
You can use the custom format and use the type : 00000
Write the following formula in front of that zip column:
=IF(LEN(A1)>5,"Invalid",RIGHT("00000" & A1,5))
Just replace the cell reference name A1 to the first cell of zip code column and then drag the cell down. Now all those zip codes that are less than five characters will be filled with leading zeros. Also It will show Invalid in cells which have a zip code of more than 5 characters length.
Apply this formula to the cell values, i.e. for A1 in this example:
=TEXT(A1,"0000#")
Copy/paste the formatted values (as text) into the desired column if you need them in a specific column.
Simply mark the whole column.
Than right click to get into the "format cells" settings.
There you go to "special format" and there you should mark "ZipCode".
Here is a picture of the options. It is in german, so I hope you will find it anyway ;)
Quick macro to convert the range to Text format, and append leading zeros if the cell is less than 5 characters.
Sub AddLeadingZeros()
Dim rng As Range: Set rng = Range("A1:A10") '<modify as needed, the cells containing ZIP'
Dim cl As Range
rng.NumberFormat = "#"
For Each cl In rng
If Len(cl.Value) < 5 Then
Do
cl.Value = "0" & cl.Value
Loop While Len(cl.Value) < 5
End If
Next
End Sub
select your column
Format-> cell
Special format-> zip code
make sure you save the changes... it shouldn't remove zero...
or try a "user defined" format... but I never tried it.
Related
I´m trying to remove the dollar sign in a column which should only include numbers. Therefore I tried to to use simply change the cell format to number but nothing changed.
Now I copied the values inside a text editor and removed the dollar signs. After inserting excel automaticallly changes some values to different numbers.
For Exaxmple it changed 8.59 to 21763,00. When I change the cell format to standard then it displays me something like 28 Jan except 8.59.
In this picture I tried to illustrate my problem with the different columns. Sold Price in Thousands is the original column which I liked to change.
Select the cells you wish to fix and run this short macro:
Sub FixData()
Dim r As Range, s As String
For Each r In Intersect(Selection, ActiveSheet.UsedRange)
s = r.Text
If Left(s, 1) = "$" Then
r.Clear
r.Value = Mid(s, 2)
r.NumberFormat = "0.00"
End If
Next r
End Sub
this is a known issue and the only work around that you can use is the following:
Copy the correct values in notepad.
From notepad make a Find and Replace in order to remove the $ sign.
Select a blank column in excel and set its format to TEXT.
Only now you can copy back the values from notepad to the new TEXT column.
This should fix your issue.
The two columns look like on this image.
When I want to show only the cells which contain a letter 'b', I can no longer see the text "Title1" and "Title2" which is normally visible in the column B.
I guess although the cells in column B are merged, the text is still bound to A3, respectively to A7.
So how can I at the same time filter the visible content and preserve the merged text? In simple words, I want to filter content by letter 'b' and I still want to see the text "title 1/2" in the column B.
You tagged excel so here is a solution in excel:
You need to click on that column with the merged cells and unmerge all cells.
Then you need to put this formula at the top of your list and enter it with ctrl+shift+enter(this will enter it as an array formula):
=OFFSET(C3,MAX(IF(NOT(ISBLANK(C$3:C3)),ROW(C$3:C3),0))-ROW(C3),0)
Then you need to autofill that down.(this function seems a little verbose but I just got it online - there is probably a simpler way to do this - but it finds the last nonblank cell in a range).
I think openoffice has similar functions so you should be able do the same or something similar in openoffice.
Alternatively if you are using excel you could click on the column you want to unmerge and run this macro:
Sub UnMergeSelectedColumn()
Dim C As Range, CC As Range
Dim MA As Range, RepeatVal As Variant
For Each C In Range(ActiveCell, Cells(Rows.Count, ActiveCell.Column).End(xlUp))
If C.MergeCells = True Then
Set MA = C.MergeArea
If RepeatVal = "" Then RepeatVal = C.Value
MA.MergeCells = False
For Each CC In MA
CC.Value = RepeatVal
Next
End If
RepeatVal = ""
Next
End Sub
Good Luck.
EDIT:
I found a Non-VBA solution that will work in both excel and openoffice and doesn't require you to enter it as an array formula(with ctrl+shift+enter):
=INDEX(B:B,ROUND(SUMPRODUCT(MAX((B$1:B1<>"")*(ROW(B$1:B1)))),0),1)
In open office I think you want to enter it like this:
=INDEX(B:B;ROUND(SUMPRODUCT(MAX((B$1:B2<>"")*(ROW(B$1:B2)))),0),1)
or maybe like this:
=INDEX(B:B;ROUND(SUMPRODUCT(MAX((B$1:B2<>"")*(ROW(B$1:B2)))),0))
You just need to autofill that formula down:
Your main problem seems to be the one "blank row" that you have left after the filter fields.
Remove it, and it will work fine.
Excel 2007- I have countless old Word Tables that I'd like to put into Excel. I'd like to split the contents of the cell into two cells. Most of the cells have a very similar format (I don't need to split the ones without this format)- Text (Date). I've tried using "LEFT" or "RIGHT" but since the text string and date string are variable lengths there are no good straightforward ways. For example-
Cell A1-
"Market Value (6/16/09)" [or "Addition (12/15/09)", etc.]
I'd like to split the cell into-
Cell A1- "Market Value" and
Cell B1- "6/16/09"
Obviously if it takes the A1 data and puts it into B1/C1 I could care less.
I've seen some other split VBA modules but they don't seem to be doing the trick for me. I've looked for ways to split it using CSV but that doesn't seem to be useful either. So is there a way to use the "(" or ")" as a marker to copy text before or after the "("?
So is there a way to use the "(" or ")" as a marker to copy text before or after the "("?
Yes
Example
Cell A1- "Market Value (6/16/09)"
Sub Sample()
Dim Ar() As String
Ar = Split(Range("A1").Value, "(")
Debug.Print Ar(0) '<~~ This will give Market Value
Debug.Print Ar(1) '<~~ This will give 6/16/09)
'<~~ And the below will give you 6/16/09
Debug.Print Replace(Ar(1), ")", "")
End Sub
I have an Excel file that looks like this. How would I change the cell formatting so that it looks exactly like it does it the function bar. Instead of 3E-07 --> 0.000003
I don't want to change the decimal places because I only want it to have the number of decimal places it needs so there won't be extra zeroes at the end.
For example because the smallest numbers have 7 decimal places if I change the whole column to seven decimal places numbers like 6E-05 will have two extra zeroes (0.0000600) at the end.
I'm trying to do this on macro because there are a lot of numbers to go through. I can set up the loop myself.
To fix on all columns, follow below steps:-
Click on the symbol mentioned side of A column (That is left side of A)
When you click on that symbol, it will select whole sheet
Double Click on border line between A column & B column
This is fix all your problems on the excel sheet
This number format issue is occurred due to column size.
To fix this type of number format "0.0000600":-
select the Column header (that is A column, B column .. and soon which ever column you need to format)
Right click on the tab
Select "Format Cell"
Click on custom option under Category
under Type field, enter 0.0000000000
Then it fix your format issue.
You have tagged this question with VBA so here are two examples of VBA's .AutoFit method.
For the entire worksheet:
With ActiveSheet 'set this worksheet reference more defintively!
.Cells.EntireColumn.AutoFit
End With
If you have columns that are already the width you want you could test the first 20 rows to see if the .TEXT property is displaying the hash mark (e.g. # or Chr(35)) symbol.
With ActiveSheet 'set this worksheet reference properly!
With .Cells(1, 1).CurrentRegion
For c = 1 To .Columns.Count
For r = 1 To 20 'maybe even .Rows.Count for smaller data grids
If CBool(InStr(1, .Cells(r, c).Text, Chr(35), vbBinaryCompare)) Then
.Columns(c).EntireColumn.AutoFit
Exit For
End If
Next r
Next c
End With
End With
The latter defined the range of cells to work on using the .CurrentRegion property which expands from its origin until it meets a fully blank row and column.
I have a long list of names that I need to have quotes around (it can be double or single quotes) and I have about 8,000 of them. I have them in Excel without any quotes and I can copy all of the names and paste them no problem but there are still no quotes. I have looked and looked for an Excel formula to add quotes to the name in each row but I have had no luck. I have also tried some clever find and replace techniques but no have worked either. The format I am looking for is this:
"Allen" or 'Allen'
Any of those would work. I need this so I can store the info into a database. Any help is greatly appreciated. Thanks
PS:
I have found other people online needing the same thing done that I need done and this solution has worked for them but I do not know what do with it:
You can fix it by using a range
variable (myCell for example) and then
use that to iterate the 'selection'
collection of range objects, like so
Sub AddQuote()
Dim myCell As Range
For Each myCell In Selection
If myCell.Value <> "" Then
myCell.Value = Chr(34) & myCell.Value
End If
Next myCell
End Sub
Another solution that also worked for others was:
Sub OneUglyExport()
Dim FileToSave, c As Range, OneBigOleString As String
FileToSave = Application.GetSaveAsFilename
Open FileToSave For Output As #1
For Each c In Selection
If Len(c.Text) <> 0 Then _
OneBigOleString = OneBigOleString & ", " & Chr(34) & Trim(c.Text) & Chr(34)
Next
Print #1, Mid(OneBigOleString, 3, Len(OneBigOleString))
Close #1
End Sub
To Create New Quoted Values from Unquoted Values
Column A contains the names.
Put the following formula into Column B
= """" & A1 & """"
Copy Column B and Paste Special -> Values
Using a Custom Function
Public Function Enquote(cell As Range, Optional quoteCharacter As String = """") As Variant
Enquote = quoteCharacter & cell.value & quoteCharacter
End Function
=OfficePersonal.xls!Enquote(A1)
=OfficePersonal.xls!Enquote(A1, "'")
To get permanent quoted strings, you will have to copy formula values and paste-special-values.
Assuming your data is in column A, add a formula to column B
="'" & A1 & "'"
and copy the formula down. If you now save to CSV, you should get the quoted values. If you need to keep it in Excel format, copy column B then paste value to get rid of the formula.
Easier steps:
Highlight the cells you want to add the quotes.
Go to Format–>Cells–>Custom
Copy/Paste the following into the Type field: \"#\" or \'#\'
Done!
Why not just use a custom format for the cell you need to quote?
If you set a custom format to the cell column, all values will take on that format.
For numbers....like a zip code....it would be this '#'
For string text, it would be this '#'
You save the file as csv format, and it will have all the quotes wrapped around the cell data as needed.
Or Select range and Format cells > Custom \"#\"
If you save the Excel file as a CSV format file, you might find that the result is convenient to inserting into a database, though I'm not sure all of the fields would be quoted.
I would like to thank Guria for the answer
from https://www.exceldemy.com/
I would like to summarize the methods, there are more than 4 methods:
Let A1 be your cell where you want to insert quotes.
1 .
For Double Quotes:
=CHAR(34)&A1&CHAR(34)
For Single Quotes:
=CHAR(39)&A1&CHAR(39)
2 .
=CONCATENATE("'",A1,"'")
3 .
="'"&A1&"'"
4 . Apply Custom Format.
Suppose you have a number and you have to insert quotes on that number:
Right click the cells:
Then click Format Cells
You will get this screen:
In the Type box write
'#'
Click 'OK' at the bottom of the screen.
You will get the result:
If you have text written in the cell then:
Click 'OK' at the bottom of the screen.