Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference cell value as string in Excel

Tags:

format

excel

cell

In Excel, if the cell A1 has some value that gets formatted in a specific way, is there a way for cell B1 to reference the string displayed in A1?

To clarify:

  • If A1 displays, for instance, the time 10:31:48, I wish to have B1 reference this outputted string as shown to the user ("10:31:48", not the underlying numerical representation "0.43875").
  • I'm well aware that there are functions for manually formatting values. However, what I'm looking for is copying an already formatted value from another cell, no matter what format that cell may have.

Is something like this possible?

like image 699
BambooleanLogic Avatar asked May 28 '13 07:05

BambooleanLogic


People also ask

How do you reference a cell in a string in Excel?

Usually you type =A1 for referring to the cell A1 in Excel. But instead, there is also another method: You could use the INDIRECT formula. The formula returns the reference given in a text. So instead of directly linking to =A1, you could say =INDIRECT(“A1”).

How do you refer to a text as string is in Excel?

Text strings are also created in Excel and Google Sheets by entering an apostrophe ( ' ) as the first character of data. The apostrophe is not visible in the cell but forces the program to interpret whatever numbers or symbols are entered after the apostrophe as text.


1 Answers

In fact, Excel stores datetime as a number, so you have to explicitly set format of the cell to see the proper value.

You may want to use TEXT function, but anyway, you have to specify format of output string:

=TEXT(A1,"hh:mm:ss")

Another option is to write your own VBA function, which can convert a value of a cell based on it's format:

Public Function GetString(ByVal cell As Range) As String
 GetString = Format(cell, cell.NumberFormat)
End Function

This will give you a result based on source cell's format

like image 190
Andrey Gordeev Avatar answered Oct 15 '22 00:10

Andrey Gordeev