Column to string excel

I want to take a list of names that are in multiple rows and combined them into a single cell like this:

Joe
Bob
George

and convert that into one cell that has this:

«Joe», «Bob», «George»

ChrisWue's user avatar

ChrisWue

18.4k4 gold badges60 silver badges83 bronze badges

asked Jun 18, 2010 at 18:22

leora's user avatar

leoraleora

186k354 gold badges871 silver badges1362 bronze badges

6 Answers

Try using TRANSPOSE function and pressing F9 on it:

+---+--------+
|   |   A    |
+---+--------+
| 1 | Joe    |
| 2 | Bob    |
| 3 | George |
+---+--------+

B1: (type in function bar)

=TRANSPOSE(A1:A3)

Highlight TRANSPOSE(A1:A3), and press F9.

It will give you:

{"Joe","Bob","George"}

Copy and paste that list. That’s it.

To concatenate the words, you just have to do:

=CONCATENATE(TRANSPOSE(A1:A3))

Highlight TRANSPOSE(A1:A3), press F9, then remove the brackets:

=CONCATENATE("Joe","Bob","George")

Zack's user avatar

Zack

2,1871 gold badge7 silver badges12 bronze badges

answered Dec 26, 2014 at 17:05

live-love's user avatar

live-lovelive-love

47.1k22 gold badges231 silver badges200 bronze badges

0

There are two basic ways that I know of.

Quickest way —

  1. Column A lists your names
  2. Copy the value of A1 to B1 — «Joe»
  3. In B2, enter the formula `=B1 & «, » & A2`
  4. Select B2, Copy the formula, and paste down the rest of column B the entire length of column A. The last cell in column B will contain a comma separated list of values from column A.

Better way —
Make your own vb function that iterates across a range of cells, and instead of summing them like sum, just concatenate them.

I do this all the time, so if anyone knows of an actual built-in Excel function buried somewhere in MS documentation that concatenates ranges, you will save the day.

answered Jun 18, 2010 at 19:15

bob-the-destroyer's user avatar

Add this as a macro to the Excel sheet and use it as a custom function with range and delimiter as input

Function Concat(myRange As Range, Optional myDelimiter As String) As String
  Dim r As Range
  Application.Volatile
  For Each r In myRange
    If Len(r.Text) Then
      Concat = Concat & IIf(Concat <> "", myDelimiter, "") & r.Text
    End If
  Next
End Function

Huey's user avatar

Huey

5,0746 gold badges33 silver badges44 bronze badges

answered Jun 28, 2015 at 4:30

Krishnan's user avatar

It is this easy. You might want to use in combination with trim, left, right, and find. Enjoy!

= A1 & " " & B1

answered Jun 18, 2010 at 18:30

buckbova's user avatar

buckbovabuckbova

1,2036 silver badges11 bronze badges

You can use GetString with an ADO recordset.

Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim s As String

''This is not the best way to refer to the workbook
''you want, but it is very conveient for notes
''It is probably best to use the name of the workbook.

strFile = ActiveWorkbook.FullName

strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
    & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open strCon

strSQL = "SELECT * " _
       & "FROM [Sheet1$A:A] "

rs.Open strSQL, cn, 3, 3

''http://www.w3schools.com/ado/ado_getstring.asp
''str = rs.GetString(format,rows,coldel,rowdel,nullexpr)
s = rs.GetString(, , , ", ")
ActiveSheet.Range("B1") = s

''Tidy up
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

answered Jun 18, 2010 at 19:39

Fionnuala's user avatar

FionnualaFionnuala

90.1k7 gold badges110 silver badges148 bronze badges

Содержание

  1. Is there a way in Excel to take a column and convert it to a concatenated string
  2. 6 Answers 6
  3. Related
  4. Hot Network Questions
  5. Subscribe to RSS
  6. Is there an easy way to turn columns-to-text without CONCATENATE in Excel?
  7. 5 Answers 5
  8. How to convert numbers to text using Excel TEXT function and other options
  9. Convert number to text using the Excel TEXT function
  10. Use the Format Cells option to convert number to text in Excel
  11. Add an apostrophe to change number to text format
  12. Convert numbers to text in Excel with Text to Columns wizard
  13. Format an Excel column (or cell) as Text in C#?
  14. 10 Answers 10

Is there a way in Excel to take a column and convert it to a concatenated string

I want to take a list of names that are in multiple rows and combined them into a single cell like this:

and convert that into one cell that has this:

6 Answers 6

Try using TRANSPOSE function and pressing F9 on it:

B1: (type in function bar)

Highlight TRANSPOSE(A1:A3), and press F9 .

It will give you:

Copy and paste that list. That’s it.

To concatenate the words, you just have to do:

Highlight TRANSPOSE(A1:A3) , press F9 , then remove the brackets:

There are two basic ways that I know of.

  1. Column A lists your names
  2. Copy the value of A1 to B1 — «Joe»
  3. In B2, enter the formula `=B1 & «, » & A2`
  4. Select B2, Copy the formula, and paste down the rest of column B the entire length of column A. The last cell in column B will contain a comma separated list of values from column A.

Better way —
Make your own vb function that iterates across a range of cells, and instead of summing them like sum , just concatenate them.

I do this all the time, so if anyone knows of an actual built-in Excel function buried somewhere in MS documentation that concatenates ranges, you will save the day.

Add this as a macro to the Excel sheet and use it as a custom function with range and delimiter as input

If the Excel CONCATENATE() function won’t do what you want, this link might help.

It is this easy. You might want to use in combination with trim, left, right, and find. Enjoy!

You can use GetString with an ADO recordset.

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.20.43330

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Is there an easy way to turn columns-to-text without CONCATENATE in Excel?

I’m aware of the text-to-columns button. Can the opposite be done by selecting columns, and possibly running a macro or using a similar button?

5 Answers 5

Normally I say «Please post your code» for help/assistance writing macros, but this one is really, really simple.

ENter it in a worksheet cell like:

Or you can specify an optional delimiter, it is a space by default, but you could use any string characters:

I was intrigued by the answer @David Zemens gave using a double transpose. His answer works well. I did found one other way to get a single row into a 1 dimensional array. Also I wanted a function that could handle a column. So here is my alternate answer.

I believe the true reverse of Text-to-Columns is the formula TEXTJOIN. It will return your selected column entries into one cell in one long string separated by a delimeter that you can set on your own.

If instead what you’re interested in is «unpivoting» your column to be values in their own column, then essentially you need to create a flat file.

This is best accomplished with R’ «gather» function or Python Pandas’ «melt» function. It can also be accomplished through macros in Excel. If you don’t know macros, a more rudimentary approach is to:

  1. create a new sheet and paste all the values of your first column (assuming this is a column you want to keep) as the first column in the new worksheet (column A). Now, in column B, paste the name of the ***first column header that you want to be value in a column. For example, below you want the column header ‘red’ to be in it’s own column — maybe a «color» column. Drag ‘red’ down column B for every row where you have a unique record in column A.
  2. Then, underneath this- paste all the values in column A again, while pasting in column B the second column that you want to perform «columns to text» on (‘orange’ in the below example).
  3. Repeat for however many columns that you need to list as «text».
  4. Finally, in column C, use the values that you have in column A and column B and create an index(match(match()) to find out what value is at the intersection of the two values you have in column A and column B.

Источник

How to convert numbers to text using Excel TEXT function and other options

by Alexander Frolov, updated on March 11, 2023

This tutorial shows how to convert number to text in Excel 2016, 2013 and 2010. See how to accomplish the task with the Excel TEXT function and use number to string to specify the formatting. Learn how to change number format to text with the Format Cells… and Text to Columns options.

If you use Excel spreadsheets to store long and not so long numbers, one day you may need to convert them to text. There may be different reasons to change digits stored as numbers to text. Below you’ll find why you may need to make Excel see the entered digits as text, not as number.

  • Search by part not by the entire number. For example, you may need to find all numbers that contain 50, like in 501, 1500, 1950, etc.)
  • It may be necessary to match two cells using the VLOOKUP or MATCH function. However, if these cells are formatted differently, Excel will not see identical values as matching. For instance, A1 is formatted as text and B1 is number with format 0. The leading zero in B2 is a custom format. When matching these 2 cells Excel will ignore the leading 0 and will not show the two cells as identical. That’s why their format should be unified.

The same issue can occur if the cells are formatted as ZIP code, SSN, telephone number, currency, etc.

Note. If you want to convert numbers to words like amount to text, it’s a different task. Please check the article about spelling numbers named Two best ways to convert numbers to words in Excel.

In this article I’ll show you how to convert numbers to text with the help of the Excel TEXT function. If you are not so formula-oriented, have a look at the part where I explain how to change digits to text format with the help of the standard Excel Format Cells window, by adding an apostrophe and employing the Text to Columns wizard.

Convert number to text using the Excel TEXT function

The most powerful and flexible way to convert numbers to text is using the TEXT function. It turns a numeric value into text and allows to specify the way this value will be displayed. It’s helpful when you need to show numbers in a more readable format, or if you want to join digits with text or symbols. The TEXT function converts a numeric value to formatted text, thus the result cannot be calculated.

If you are familiar with using formulas in Excel, it will not be a problem for you to employ the TEXT function.

  1. Add a helper column next to the column with the numbers to format. In my example, it’s column D.
  2. Enter the formula =TEXT(C2,»0″) to the cell D2. In the formula, C2 is the address of the first cell with the numbers to convert.
  3. Copy the formula across the column using the fill handle.
  4. You will see the alignment change to left in the helper column after applying the formula.
  5. Now you need to convert formulas to values in the helper column. Start with selecting the column.
  6. Use Ctrl + C to copy. Then press the Ctrl + Alt + V shortcut to display the Paste Special dialog box.
  7. On the Paste Special dialog, select the Values radio button in the Paste group.

You will see a tiny triangle appear in the top-left corner of each cell in your helper column, which means the entries are now text versions of the numbers in your main column.

Now you can either rename the helper column and delete the original one, or copy the results to your main and remove the temporary column.

Note. The second parameter in the Excel TEXT function shows how the number will be formatted before being converted. You may need to adjust this based on your numbers:

The result of =TEXT(123.25,»0″) will be 123.

The result of =TEXT(123.25,»0.0″) will be 123.3.

The result of =TEXT(123.25,»0.00″) will be 123.25.

To keep the decimals only, use =TEXT(A2,»General») .

Tip. Say you need to format a cash amount, but the format isn’t available. For instance, you cannot display a number as British Pounds (ВЈ) as you use the built-in formatting in the English U.S. version of Excel. The TEXT function will help you convert this number to Pounds if you enter it like this: =TEXT(A12,»ВЈ#,###,###.##») . Just type the format to use in quotes -> insert the ВЈ symbol by holding down Alt and pressing 0163 on the numeric keypad -> type #,###.## after the ВЈ symbol to get commas to separate groups, and to use a period for the decimal point. The result is text!

Use the Format Cells option to convert number to text in Excel

If you need to quickly change the number to string, do it with the Format Cells… option.

  1. Select the range with the numeric values you want to format as text.
  2. Right click on them and pick the Format Cells… option from the menu list.

Tip. You can display the Format Cells… window by pressing the Ctrl + 1 shortcut.

You’ll see the alignment change to left, so the format will change to text. This option is good if you don’t need to adjust the way your numbers will be formatted.

Add an apostrophe to change number to text format

If these are just 2 or 3 cells in Excel where you want to convert numbers to string, benefit from adding an apostrophe before the number. This will instantly change the number format to text.

Just double-click in a cell and enter the apostrophe before the numeric value.

You will see a small triangle added in the corner of this cell. This is not the best way to convert numbers to text in bulk, but it’s the fastest one if you need to change just 2 or 3 cells.

Convert numbers to text in Excel with Text to Columns wizard

You may be surprised but the Excel Text to Columns option is quite good at converting numbers to text. Just follow the steps below to see how it works.

  1. Select the column where you want to convert numbers to string in Excel.
  2. Navigate to the Data tab in and click on the Text to Columns icon.
  3. Just click through steps 1 and 2. On the third step of the wizard, make sure you select the Text radio button.
  4. Press Finish to see your numbers immediately turn into text.

I hope the tips and tricks from this article will help you in your work with numeric values in Excel. Convert number to string using the Excel TEXT function to adjust the way your numbers will be displayed, or use Format Cells and Text to Columns for quick conversions in bulk. If these are just several cells, add an apostrophe. Feel free to leave your comments if you have anything to add or ask. Be happy and excel in Excel!

Источник

Format an Excel column (or cell) as Text in C#?

I am losing the leading zeros when I copy values from a datatable to an Excel sheet. That’s because probably Excel treats the values as a number instead of text.

I am copying the values like so:

How do I format a whole column or each cell as Text?

A related question, how to cast myWorksheet.Cells[i + 2, j] to show a style property in Intellisense?

10 Answers 10

Below is some code to format columns A and C as text in SpreadsheetGear for .NET which has an API which is similar to Excel — except for the fact that SpreadsheetGear is frequently more strongly typed. It should not be too hard to figure out how to convert this to work with Excel / COM:

Disclaimer: I own SpreadsheetGear LLC

If you set the cell formatting to Text prior to adding a numeric value with a leading zero, the leading zero is retained without having to skew results by adding an apostrophe. If you try and manually add a leading zero value to a default sheet in Excel and then convert it to text, the leading zero is removed. If you convert the cell to Text first, then add your value, it is fine. Same principle applies when doing it programatically.

Solution that worked for me for Excel Interop:

This code should run before putting data to Excel. Column and row numbers are 1-based.

A bit more details. Whereas accepted response with reference for SpreadsheetGear looks almost correct, I had two concerns about it:

  1. I am not using SpreadsheetGear. I was interested in regular Excel communication thru Excel interop without any 3rdparty libraries,
  2. I was searching for the way to format column by number, not using ranges like «A:A».

Before your write to Excel need to change the format:

I’ve recently battled with this problem as well, and I’ve learned two things about the above suggestions.

  1. Setting the numberFormatting to @ causes Excel to left-align the value, and read it as if it were text, however, it still truncates the leading zero.
  2. Adding an apostrophe at the beginning results in Excel treating it as text and retains the zero, and then applies the default text format, solving both problems.

The misleading aspect of this is that you now have a different value in the cell. Fortuately, when you copy/paste or export to CSV, the apostrophe is not included.

Conclusion: use the apostrophe, not the numberFormatting in order to retain the leading zeros.

Use your WorkSheet.Columns.NumberFormat , and set it to string «@» , here is the sample:

Note: this text format will apply for your hole excel sheet!

If you want a particular column to apply the text format, for example, the first column, you can do this:

or this will apply the specified range of woorkSheet to text format:

Источник

Given an existing Excel 2003 document with cells of any type (integers, text, decimal, etc), how do I convert the contents of every cell to text?

And save all these changes in the same excel document?

asked Apr 13, 2010 at 18:29

Justin Tanner's user avatar

Justin TannerJustin Tanner

6353 gold badges11 silver badges18 bronze badges

2

On a different sheet you can enter in cell A1:

="" & OriginalSheet!A1

Copy/Paste that for the full width and length of your original sheet. Then you can Paste Special>Values bock over the originals. That should make everything have your little green patch.

The only caveat is dates. When you apply this formula to a date field it will show the serial number of the date as text. Not the normal formatting you would have applied. To get around this, use this formula instead of the one above for date fields:

=TEXT(A1,"mm/dd/yyyy")

answered Apr 14, 2010 at 13:42

Sux2Lose's user avatar

1

Here is the definitive answer:

highlight the numbers and use the Data > Text to Columns command. In Page 1 of the wizard, choose the appropriate type (this will probably be Delimited). In Page 2, remove any column dividers that may have shown up to keep the data in one column. In Page 3, click Text under Column data format to indicate that this column is text.

answered Apr 4, 2012 at 18:39

Matt Trifiro's user avatar

1

You can select all the fields, right click and copy, then right click and paste special/values. You probably want to copy into a new spreadsheet so you don’t lose your formulas.

Then select all the fields and do as Mark Robinson suggested: click Format Cells and chose text.

This will covert all formulas into the value they represent instead of a formula and then covert the values that are number into text.

answered Apr 13, 2010 at 20:40

Zooks64's user avatar

Zooks64Zooks64

2,00214 silver badges14 bronze badges

4

Select all your cells Ctrl+a

Right click on the selected cells and click Format Cells

Under the Number tab select Text as the Category

Text format cells are treated as text
even when a number is in the cell.
The cell is displayed exactly as
entered.

Then save your excel document

answered Apr 13, 2010 at 18:57

Mark's user avatar

MarkMark

4783 silver badges12 bronze badges

1

The only way that I was able to overcome the problem of retaining only text from numbers and texts was to save my file as a .csv then close it and reopen it .. all data is then text and the file can then be saved as a .xlsx or whatever and formulae added. This enabled me to compare data from different sources and return values correctly.

answered Mar 6, 2021 at 18:51

Rosalind's user avatar

Transform a Column to a String — Microsoft Community Hub

Details: WebTransform a Column to a String Excel (Google Sheets) 1. How to convert column to string? 2. How to transform the column (or row) by putting after each … how to combine two columns in excel

› Verified 8 days ago

› Url: Techcommunity.microsoft.com View Details

› Get more: How to combine two columns in excelDetail Excel

Convert Columns to Text in Excel – Excel Tutorial — OfficeTuts Excel

Details: WebColumns to text with an ampersand Let’s start with an ampersand. Enter the following formula into a cell. 1 =A1&» «&B1&» «&C1&» «&D1&E1 This is how it looks like. Columns … columns to text in excel

› Verified 4 days ago

› Url: Officetuts.net View Details

› Get more: Columns to text in excelDetail Excel

How to convert number to text in Excel — 4 quick ways

Details: WebSelect the column where you want to convert numbers to string in Excel. Navigate to the Data tab in and click on the Text to Columns icon. Just click through … how to set up columns in excel

› Verified Just Now

› Url: Ablebits.com View Details

› Get more: How to set up columns in excelDetail Excel

How to Convert Column to Text with Delimiter in Excel

Details: Web5 Easy Ways to Convert Column to Text with Delimiter in Excel 1. Applying TEXTJOIN Function 2. Using CONCAT Function 3. Applying VBA Code 4. Applying Ampersand Operator 5. Using a … excel convert column to text

› Verified Just Now

› Url: Exceldemy.com View Details

› Get more: Excel convert column to textDetail Excel

Split text into different columns with functions — Microsoft …

Details: WebYou can use the LEFT, MID, RIGHT, SEARCH, and LEN text functions to manipulate strings of text in your data. For example, you can distribute the first, middle, and last names from a single cell into three separate … how to change excel columns to numbers

› Verified 8 days ago

› Url: Support.microsoft.com View Details

› Get more: How to change excel columns to numbersDetail Excel

How to convert column list to comma separated list in …

Details: WebIn the opening Combine Columns or Rows dialog box, you need to: (1) Check the Combine rows option in the To combine selected cells according to following options section; (2) In the Specify a separator section, check … excel vba convert to string

› Verified 9 days ago

› Url: Extendoffice.com View Details

› Get more: Excel vba convert to stringDetail Excel

Convert time fields to strings in Excel — Stack Overflow

Details: WebIn cell B1 enter this formula: =TEXT (A1,»hh:mm:ss AM/PM») , drag the formula down column B to the end of your data in column A. Select the values from …

› Verified 2 days ago

› Url: Stackoverflow.com View Details

› Get more:  ExcelDetail Excel

How to convert columns to text in Excel WPS Office …

Details: Web1.To open a WPS Visual Basic for Application window, use F11 on the keyboard while holding down the ALT button.Copy the VBA into the module by selecting …

› Verified 2 days ago

› Url: Wps.com View Details

› Get more:  ExcelDetail Excel

Convert numbers to text — Excel formula Exceljet

Details: WebSummary. To convert numbers into text values, you can use the TEXT function. In the example shown, the formula in C5 is: = TEXT (B5,»0″) The result is the number 1021 formatted as text «1021». All numbers in …

› Verified 3 days ago

› Url: Exceljet.net View Details

› Get more:  ExcelDetail Excel

How to Convert Formula Result to Text String in Excel (7 Easy Ways)

Details: WebWe can easily convert formula results to text string by using the Copy & Paste feature of Excel. Let’s go through the procedure below. Steps: First, select the …

› Verified Just Now

› Url: Exceldemy.com View Details

› Get more:  ExcelDetail Excel

Convert Column to Comma Separated List Online

Details: WebUse this tool to convert a column into a Comma Separated List. Copy your column of text in Excel. Paste the column here (into the leftmost textbox) Copy your comma separated …

› Verified 1 days ago

› Url: Convert.town View Details

› Get more:  ExcelDetail Excel

Text to Columns in Excel — Examples, Shortcut, How to Use/Convert

Details: WebStep 3: Select the Text to Columns option from the Data Tools group. Step 4: The window Convert Text to Columns Wizard – Step 1 of 3 opens. Step 5: Select the Delimited …

› Verified 1 days ago

› Url: Excelmojo.com View Details

› Get more:  ExcelDetail Excel

How to convert number to text in Excel — 4 quick ways Convert a …

Details: WebThis tutorials shows how up convert number to text is Excel 2016, 2013, and 2010. See how go accomplish the task with to Choose TEXT key and exercise …

› Verified 8 days ago

› Url: Substance-strategies.com View Details

› Get more:  ExcelDetail Excel

How to Convert Column to Row in Excel? — WebNots

Details: WebAfter copying the content, simply right click on the cell where you want to paste and choose “Transpose” option. This will paste the content by converting rows …

› Verified 2 days ago

› Url: Webnots.com View Details

› Get more:  ExcelDetail Excel

How to convert column data to row or vice versa? : r/excel — Reddit

Details: WebOnce your problem is solved, reply to the answer (s) saying Solution Verified to close the thread. Follow the submission rules — particularly 1 and 2. To fix the body, click edit. To …

› Verified 6 days ago

› Url: Reddit.com View Details

› Get more:  ExcelDetail Excel

Convert YYYYMMDD to MM/DD/YYYY in Excel (Step-by-Step)

Details: WebMethod 1 – Using Text-to-Columns to Convert yyyymmdd to mm/dd/yyyy in Excel. The Text-to-Column method is the best way to convert yyyymmdd to mm/dd/yyyy in the …

› Verified Just Now

› Url: Spreadsheetplanet.com View Details

› Get more:  ExcelDetail Excel

Convert Date To Text In Excel Explained With Examples

Details: WebHere are the steps to do this: Select all the cells that contain dates that you want to convert to text. Go to Data –> Data Tools –> Text to Column. In the Text to …

› Verified 9 days ago

› Url: Exceljetak.pages.dev View Details

› Get more:  ExcelDetail Excel

How to Convert Numbers to Text in Excel – 4 Super Easy Ways

Details: WebSelect the numbers in Column A. Click the Data tab. Click on the Text to Columns icon in the ribbon. This will open the text to columns wizard this will open the text to column

› Verified 3 days ago

› Url: Trumpexcel.com View Details

› Get more:  ExcelDetail Excel

How to convert multiple columns to text in Excel?

Details: Web1.Pick the group that includes the entire names. 2.Click Text to Columns under the Data Tools section of the Data tab. 3.The dialogue window shown below …

› Verified 1 days ago

› Url: Wps.com View Details

› Get more:  ExcelDetail Excel

5 Ways to Convert Text to Numbers in Microsoft Excel — How-To …

Details: WebSelect all of the cells that you need to convert to numbers from text. Either right-click and choose Paste Special > Paste Special or go to the Home tab and choose …

› Verified 3 days ago

› Url: Howtogeek.com View Details

› Get more:  ExcelDetail Excel

How to convert Text to Columns in Excel — TheWindowsClub

Details: WebHow to convert Text to Columns in Excel. Follow the steps below to convert text to columns in Excel: Launch Excel. Enter some data into a single cell, for …

› Verified Just Now

› Url: Thewindowsclub.com View Details

› Get more:  ExcelDetail Excel

Converting Excel Column Type From Int to String in Python

Details: WebI’m trying to figure out how to convert the entire column of a spreadsheet from an int to a string. Converting Excel Column Type From Int to String in Python. …

› Verified 2 days ago

› Url: Stackoverflow.com View Details

› Get more:  ExcelDetail Excel

Pandas Convert Column Values to String Delft Stack

Details: WebIt changes the data type of the Age column from int64 to object type representing the string.. Convert the Data Type of All DataFrame Columns to string

› Verified 6 days ago

› Url: Delftstack.com View Details

› Get more:  ExcelDetail Excel

Converting a Text File to Excel Spreadsheet – How it Works — Earn

Details: WebConvert a text file with CSV record into an Excel excel. The column brake remains represented with a line having a needle. To move an line break, you will have to …

› Verified 9 days ago

› Url: Picassohr.com View Details

› Get more:  ExcelDetail Excel

This article is brought to you by Datawrapper, a data visualization tool for creating charts, maps, and tables. Learn more.

All Blog Topics

feature image

Sometimes, your data comes with several pieces of information in one column. Like a column with U.S. states in the format US-TX. Or a column with companies and the product they sell: Datawrapper (Software).

But say you want country (US) separate from state (TX) — for example, to create a Datawrapper choropleth map. Good thing there are easy ways to separate data points into two or more columns.

I’ll show two ways to create multiple new columns out of one old column. We’ll use Google Sheets — but the same tricks should work with LibreOffice Calc, Excel, or any other spreadsheet software.

The first method is the formula =SPLIT():

1st method

Split columns with SPLIT()

  1. Create at least two new columns next to the column whose data you want to split. To do so, click on the header (ABC, etc.). Then click the little triangle and select “Insert 1 right.” Repeat to create a second empty column.
  2. In the first empty column, write =SPLIT(B1,"-"), with B1 being the cell you want to split and - the character you want the cell to split on. (If you see the error #REF! in your cell, you’ll need to create more columns.)
  3. To apply the changes to the cells below, drag down the blue square in the bottom right of the selected cell(s). Double-click on the blue square to fill all remaining cells.

2nd method

Extract content from columns with LEFT()

Sometimes you don’t have clear separator characters, but just want to extract the first or last characters of a cell. To do so, use the formulas =LEFT(B1,2)=RIGHT(B1,8), and =MID(B1,2,4):

  1. Insert a new column. (Or two. Or three! As many as you need.)
  2. In the new column(s), write
    =LEFT(B1,2) to extract the first 2 characters of the cell B1.
    =RIGHT(B1,8) to extract the last 8 characters of the cell B1.
    =MID(B1,4,2) to extract the 2 characters following the 4th character in B1.
  3. To apply the changes to the cells below, drag down the blue square.

Pro tips

Pro tip 1: You can combine formulas to extract characters at all sorts of crazy positions. For example, the formula =LEN() gives back the number of characters in a cell. So =LEFT(A1,LEN(A1)-2) extracts the entire text in a cell except the last two characters. To separate the cell Datawrapper (Software) into the two cells Datawrapper and Software, you could use the formula =SPLIT(LEFT(A5,LEN(A5)-1),"(". This formula first removes the last bracket and then splits the remaining cell content on (.

Pro tip 2: Now that you learned to separate text, you can also bring it together again. To combine the column US from your cell A1 and TX from B1 with a hyphen, use ampersands and write =A1&"-"&B1.

Pro tip 3: You can extract content with LEFT()RIGHT(), and MID() not just from text cells, but also from number and date cells. If you want to apply formulas like LEFT() to your dates, it helps to transform them into a text format first. To do so, use the formula =TEXT(A1, "MM/DD/YYYY"). Instead of MM/DD/YYYY, you can use any combination of these date codes and /-, a space, etc. For example, =TEXT(A1, "dd-mmm-yyyy") will transform the date format 1st of November 2019 to a text cell with the content 01-Nov-2019.

Pro tip 4: If you have empty cells in your column, and you want them stay empty after using a function like LEFT(), you’ll need to check for these empty cells first. You can do so with the function ISBLANK(), combined with an IF function: =IF(ISBLANK(A1),"",LEFT(A1,3)).


I hope this was helpful! If you need more help cleaning your data to prepare it for a charting tool like Datawrapper, visit our article “How to prepare your data for analysis and charting in Excel & Google Sheets.” And if you have any questions, please leave a comment or write to me at lisa@datawrapper.de.


Profile image of Lisa Muth of the Datawrapper team

Lisa Charlotte Muth

(she/her, @lisacmuth, formerly Lisa Charlotte Rost) is responsible for the communication at Datawrapper, especially the blog. She’s been writing about data vis for years and is excited to learn and teach.

NEWSLETTER

  • Remove From My Forums
  • Question

  • Hiiiiiiii
    I develop a excel add ins. and i want to define a data type of column as a string.
    my problem is i want to compare two numeric value as a string.
    how can i do this.
    Please Help
    Thanx
    Mitesh Khatri

Answers

  • Here’s sample code that converts column «D» to text as the data type. It’s the equivalent of the Data/Text to columns command in the UI. Please see that and the Help for the TextToColumns method in order to understand what the various arguments in the method do.

    Excel.Range rngStringData = ws.get_Range(«D1», missing);

    rngStringData = rngStringData.EntireColumn;

    //create an array that contains the information

    //for the FieldInfo argument specifying Text as the data type

    object[,] aDataType = new object[1, 2];

    aDataType.SetValue(1, 0,0);

    aDataType.SetValue(2, 0,1);

    rngStringData.TextToColumns(rngStringData, Microsoft.Office.Interop.Excel.XlTextParsingType.xlDelimited,


    Microsoft.Office.Interop.Excel.XlTextQualifier.xlTextQualifierDoubleQuote,

    missing, missing, missing, missing, missing, missing, missing, aDataType, missing, missing, missing);

Like this post? Please share to your friends:
  • Column to one cell excel
  • Column spacing in word
  • Column sizes in excel
  • Column problems in word
  • Column problem in word