Returns the text referred to by value. If value is text, returns the text. If value is not text, returns empty string. Essential for extracting text values and filtering non-text data in Excel.
Master the fundamentals of Excel T function
The T function returns the text referred to by value. If the value is text, it returns the text unchanged. If the value is not text (number, date, logical, etc.), it returns an empty string. It's useful for extracting text values, filtering data, and ensuring text-only results.
Returns text values unchanged
Returns empty string for non-text
Can detect if value is text
Simple way to filter text values
Function-specific parameters
Function-specific return type
Extract text values from mixed data
Filter out non-text values
Check if value is text
Clean mixed data to text only
Exact matching required
Returns numeric position
Handles missing text gracefully
=T(value)The value to check. If text, returns the text. Otherwise returns empty string.
Text value or empty string
Description: Returns the text referred to by value. If value is text, returns text. If not text, returns empty string.
Returns text as-is
Text values are returned unchanged
Simple VBA implementation of T function
' Basic T in VBA
Range("B1").Value = Application.WorksheetFunction.T(Range("A1").Value)
' Using VBA T function
Dim value As Variant
value = "Hello"
Dim result As String
result = Application.WorksheetFunction.T(value)
Debug.Print result ' Output: "Hello"
' Extract text from range
Sub ExtractText()
Dim cell As Range
For Each cell In Range("A1:A10")
cell.Offset(0, 1).Value = Application.WorksheetFunction.T(cell.Value)
Next cell
End Sub
' Filter text values only
Sub FilterTextValues()
Dim cell As Range
Dim textCount As Integer
textCount = 0
For Each cell In Range("A1:A10")
Dim textValue As String
textValue = Application.WorksheetFunction.T(cell.Value)
If textValue <> "" Then
textCount = textCount + 1
cell.Offset(0, 1).Value = textValue
End If
Next cell
Debug.Print "Text values found: " & textCount
End SubComprehensive text extraction and validation
' Function to safely extract text
Function SafeT(value As Variant) As String
On Error Resume Next
SafeT = Application.WorksheetFunction.T(value)
If Err.Number <> 0 Then
SafeT = ""
Err.Clear
End If
On Error GoTo 0
End Function
' Check if value is text
Function IsTextValue(value As Variant) As Boolean
Dim tResult As String
tResult = Application.WorksheetFunction.T(value)
IsTextValue = (tResult <> "")
End Function
' Extract only text values to new range
Sub ExtractOnlyText()
Dim sourceRange As Range
Dim destRange As Range
Set sourceRange = Range("A1:A100")
Set destRange = Range("B1")
Dim cell As Range
Dim destRow As Integer
destRow = 1
For Each cell In sourceRange
Dim textValue As String
textValue = Application.WorksheetFunction.T(cell.Value)
If textValue <> "" Then
destRange.Offset(destRow - 1, 0).Value = textValue
destRow = destRow + 1
End If
Next cell
End SubExtract text values from mixed data
Filter out non-text values
Check if value is text
Combine only text values
T returns empty string for numbers/dates
=TEXT(A1, "0") for numbersSolution: This is expected. T only returns text. Use TEXT function to convert numbers to text, or VALUE to convert text to numbers.
Numbers formatted as text still return as text
=VALUE(T(A1))Solution: This is expected. If a number is stored as text (e.g., "123"), T will return it. Use VALUE to convert.
ISTEXT may be more appropriate for type checking
=ISTEXT(A1)Solution: Use ISTEXT(value) to check if value is text, or T(value)<>"" for similar result.
T with empty cell returns empty string
=IF(A1="", "Empty", T(A1))Solution: This is expected. Empty cells return empty string. Check for empty: =IF(A1="", "Empty", T(A1))