Windows 10
Excel 2019
In Column K, the cells are populated by a formula.
In some cells the formula will have nothing to return ("") and Excel inserts a (') Apostrophe which I need to remove but only for the cells where the formula has returned nothing.
I have the code below that selects Cell K2 down to the last used row.
Then for any cell that is blank it removes the (') Apostrophe.
This works and all of the Apostrophes are remove but VBA does give a Run-time error '13' Type mismatch on the line of code
I would like to ask 2 questions if I may.
1. What is causing the error and how may it be fixed?
2. Is there a better (and faster) way to do this task?
This code will be inserted at the beginning of another sub, which is an advanced filter, to prepare Column K for the filter as the Apostrophes are causing the filter not to work correctly.
Once the Apostrophes are removed the filter works perfectly.
Excel 2019
In Column K, the cells are populated by a formula.
In some cells the formula will have nothing to return ("") and Excel inserts a (') Apostrophe which I need to remove but only for the cells where the formula has returned nothing.
I have the code below that selects Cell K2 down to the last used row.
Then for any cell that is blank it removes the (') Apostrophe.
This works and all of the Apostrophes are remove but VBA does give a Run-time error '13' Type mismatch on the line of code
VBA Code:
If r.PrefixCharacter = "'" And Len(r.Value) = 0 Then
I would like to ask 2 questions if I may.
1. What is causing the error and how may it be fixed?
2. Is there a better (and faster) way to do this task?
This code will be inserted at the beginning of another sub, which is an advanced filter, to prepare Column K for the filter as the Apostrophes are causing the filter not to work correctly.
Once the Apostrophes are removed the filter works perfectly.
VBA Code:
Sub ClearApostraphie()
Dim sht As Worksheet
Dim LastRow As Long
Dim r As Range
Set sht = ActiveSheet
LastRow = sht.Range("K2").CurrentRegion.Rows.Count
sht.Range("K2", sht.Range("K" & LastRow)).Select
For Each r In ActiveSheet.UsedRange
If r.PrefixCharacter = "'" And Len(r.Value) = 0 Then
r.Clear
End If
Next r
End Sub