Forum Discussion
VBA Range Format
- Apr 05, 2022
WAW nice! Bingo!
Explain.. :
.formula means what ?
the IF is an IF excel function? if so, then F2="""" is the logical test ? does it mean if empty? why 4 of "
then , """" means value if true? and then ,TEXT(F2,""yyy-mm-dd"") if value if false?
.Numberformat = "@" will format G column as TEXT
.value (G2) = .value (F2) <-- how does it know this is F2 ?
end with (end loop)
sorry for all the questions but i want to understand it.
Thank you so much
I am guessing somewhat, but I suspect the problem is that the column contains datevalues and though applying a number format creates the correct appearance in the range, it is still a number and will be read as such. My knowledge of VBA is somewhat sketchy, but maybe something of the nature
Option Explicit
Option Base 1
Sub ToText()
'
' ToText Macro
'
Dim v As Variant
Dim i As Long, n As Long
Dim t() As Variant
Dim rng As Range
'
Set rng = Range("dates")
v = rng.Value
n = UBound(v, 1)
ReDim t(n, 1)
For i = 1 To n
t(i, 1) = "'" & Application.WorksheetFunction.Text(v(i, 1), "yyyy-mm-dd")
Next i
rng.Value = t
End Submight provide a start.