Answer the question
In order to leave comments, you need to log in
How to convert DATE to TEXT format in Excel cells?
In the cells DATE (TIME)
---
6:10:00
6:15:00
---
If we change the cell type to text, we get accordingly:
---
0.256944444444444
0.260416666666667
---
I need to concatenate the data in date cells.
And accordingly my code inserts text values like "0.2604".
Please help me convert DATE to TEXT.
How is it done in VBA?
Sub qqwe2()
Dim r As Long, rn As Range
Set rn = Intersect(ActiveSheet.UsedRange, [B:B])
For r = rn(rn.Count).Row To rn(1).Row Step -1
If Cells(r, 1) <> Empty Then
Cells(r, 1).Formula = Now
date_str2 = CStr(Cells(r, 1).Value)
Cells(r, 1).Value = "ANCHOR " & date_str & ":00:00"
End If
Next
End Sub
Answer the question
In order to leave comments, you need to log in
In fact, everything is very simple if you have VBA in your hands
. We create a module, add a function, call the function on the sheet.
Public Function ToText(ByRef rng As Range) As String
ToText = rng.Text
End Function
I won’t tell you the code directly, but try the following: start recording a macro, then do everything in Excel with your hands, stop recording and figure out what happened in the macro
Sub get_text_from_data()
Dim a As Object
Dim b As Range
Set a = ActiveSheet. Range("C5")
Set b = ActiveSheet.Range("C6")
a = a.Text
b = b.Text
With ActiveSheet.Range("D102")
.Value = a + b
End With
End Sub
This is just an example of what would refer to the self-willedness of the .Text cell
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question