Replace the first character in a cell from a selected range

Marc_w90

Board Regular
Joined
Jul 11, 2014
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have an array of indirect formulae (K2:N44), which as you can image are slowing down the processing on the sheet and annoying users.
Fortunately, these formula aren't a necessity at all times.

I was hoping to therefore make a macro which would remove the "=" from the first character in the cells and then another macro to add it back in as the first character.
Not used VBA in some years was hoping there was a simple solution.

Thanks,
Marc
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Am not entirely sure your idea (or indeed my solution) is the best method of doing this but I can't think of another.
So...

Code:
Sub RemoveEqualSign()
For i = 11 To 14
    For j = 2 To 44
        If Cells(j, i).Formula <> "" Then
            k = Cells(j, i).Formula
            l = Right(k, Len(k) - 1)
            Cells(j, i) = l
        End If
    Next j
Next i
End Sub

Sub AddEqualSign()
For i = 11 To 14
    For j = 2 To 44
        If Cells(j, i).Formula <> "" Then
            k = Cells(j, i).Formula
            l = "=" & k
            Cells(j, i).Formula = l
        End If
    Next j
Next i
End Sub
 
Upvote 0
Do any of the cells in the range K2:N44 have an equals sign in any position other than at the start?
 
Upvote 0
Just having to go out
If the equals sign is only at the start try
VBA Code:
Sub RemoveEqualSigns()
  Range("K2:N44").Replace "=", "", xlPart
End Sub

to add it back in try
VBA Code:
Sub AddEqualSigns()
    With Range("K2:N44")
        .Value = Evaluate("IF(" & .Address & "<>"""",""=""&" & .Address & ","""")")
    End With
End Sub
 
Upvote 0
Unfortunately some of the formulae have "=" within the formula itself as well, hence me wanting to target the first character.
 
Upvote 0
Am not entirely sure your idea (or indeed my solution) is the best method of doing this but I can't think of another.
So...

Code:
Sub RemoveEqualSign()
For i = 11 To 14
    For j = 2 To 44
        If Cells(j, i).Formula <> "" Then
            k = Cells(j, i).Formula
            l = Right(k, Len(k) - 1)
            Cells(j, i) = l
        End If
    Next j
Next i
End Sub

Sub AddEqualSign()
For i = 11 To 14
    For j = 2 To 44
        If Cells(j, i).Formula <> "" Then
            k = Cells(j, i).Formula
            l = "=" & k
            Cells(j, i).Formula = l
        End If
    Next j
Next i
End Sub
This is very close.
The removal of the "=" sign seems to work fine and breaks my formulae as intended.

However, I can't get the addition of an "=" as the first character to work.
I just get a Run-time error, application defined or object defined error.
Is it because your code implies the text in there is a formula, which now they have all had the "=" sign at the beginning removed, they are not formula?

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top