The code will read your IsText
as an undeclared variable. Therefore the code will check if the value in column E is "equal to nothing". This code should do the trick:
Option Explicit
Sub MoveJobFunctions()
Dim row As Long
For row = 2 To 1000
'Check if is text
If Excel.WorksheetFunction.IsText(Range("E" & row).Value) And Not IsDate(Range("E" & row).Value) Then
' Copy the value and then blank the source.
Range("A" & row).Value = Range("E" & row).Value
Range("E" & row).ClearContents
End If
Next
End Sub
As you can see, Excel.WorksheetFunction.IsText
the proper way to use the IsText
function. I've added the Option Explicit
statement that will require you to declare any variable (or an error will occur). It will help you spot errors like the one that made your code uneffective. I've also added a line to clear the source value (as specified in your code's comment).
Note added after new comments: i've added an IsDate
function to check if the value is a date. IsDate
is a function stored in the VBA.Information
library. Since it's a VBA function, you don't need to specify the entire address as for the IsText
function which is a Excel function (and it's stored in Excel.WorksheetFunction
library). More information about IsDate
here.
In order to cover only the list and not the whole sheet (or an hardcoded number of rows) you can use some trick like the ones in this link. A possible code (if there is nothing under the list) could be this one:
Option Explicit
Sub MoveJobFunctions()
Dim row As Long
Dim lastrow As Long
lastrow = Range("E" & Cells.Rows.Count).End(xlUp).row
For row = 2 To lastrow
'Check if is text
If Excel.WorksheetFunction.IsText(Range("E" & row).Value) And Not IsDate(Range("E" & row).Value) Then
' Copy the value and then blank the source.
Range("A" & row).Value = Range("E" & row).Value
Range("E" & row).ClearContents
End If
Next
End Sub
In case the list is an uninterrupted series of data, you could use this code:
Option Explicit
Sub MoveJobFunctions()
Dim row As Long
Dim lastrow As Long
lastrow = Range("E2").End(xlDown).row
For row = 2 To lastrow
'Check if is text
If Excel.WorksheetFunction.IsText(Range("E" & row).Value) And Not IsDate(Range("E" & row).Value) Then
' Copy the value and then blank the source.
Range("A" & row).Value = Range("E" & row).Value
Range("E" & row).ClearContents
End If
Next
End Sub
Or this one:
Option Explicit
Sub MoveJobFunctions()
Dim cell As Range
Set cell = Range("E2")
Do Until cell.Value = ""
'Check if is text
If Excel.WorksheetFunction.IsText(cell.Value) And Not IsDate(cell.Value) Then
' Copy the value and then blank the source.
Range("A" & cell.row).Value = cell.Value
cell.ClearContents
End If
'Offsetting cell down to the next row.
Set cell = cell.Offset(1, 0)
Loop
End Sub