vba Remove text from Formula

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
657
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I have this formula in several cells containing "*". I'd like to remove the "*" from the formulas.
The range of cells with "*" in the formula is Z2:CN4.
Thank you.

Here is a limited example:

Wagers.xlsm
YZAAABACAD
1M-Q-R:V-X:Z-W (6)M-Q-R:V-Y:Z-W (6)M-R:V-X:Z-W (6)
2W:0W:0W:0
3L:0L:0L:0
4Psh:0Psh:0Psh:0
NBA
Cell Formulas
RangeFormula
Y1Y1="M-Q-R:V-X:Z-W"&" ("&RANK(Y9,$Y$9:$CN$9)&")"
AA1AA1="M-Q-R:V-Y:Z-W"&" ("&RANK(AA9,$Y$9:$CN$9)&")"
AC1AC1="M-R:V-X:Z-W"&" ("&RANK(AC9,$Y$9:$CN$9)&")"
Z2Z2=COUNTIFS($L$3:$L$1190,"*M-Q-R:V-X:Z-W*",$A$3:$A$1190,"W")+(Z4*0.5)
Z3Z3=COUNTIFS($L$3:$L$1190,"*M-Q-R:V-X:Z-W*",$A$3:$A$1190,"L")+(Z4*0.5)
Z4Z4=COUNTIFS($L$3:$L$1190,"*M-Q-R:V-X:Z-W*",$A$3:$A$1190,"psh")
AB2AB2=COUNTIFS($L$3:$L$1190,"*M-Q-R:V-Y:Z-W*",$A$3:$A$1190,"W")+(AB4*0.5)
AB3AB3=COUNTIFS($L$3:$L$1190,"*M-Q-R:V-Y:Z-W*",$A$3:$A$1190,"L")+(AB4*0.5)
AB4AB4=COUNTIFS($L$3:$L$1190,"*M-Q-R:V-Y:Z-W*",$A$3:$A$1190,"psh")
AD2AD2=COUNTIFS($L$3:$L$1190,"*M-R:V-X:Z-W*",$A$3:$A$1190,"W")+(AD4*0.5)
AD3AD3=COUNTIFS($L$3:$L$1190,"*M-R:V-X:Z-W*",$A$3:$A$1190,"L")+(AD4*0.5)
AD4AD4=COUNTIFS($L$3:$L$1190,"*M-R:V-X:Z-W*",$A$3:$A$1190,"psh")
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
modify this to your need. if it helps you pl mark it as a solution for the benefit of future readers of the thread.
VBA Code:
Sub Macro1()
Dim range1 As Range
Set range1 = Range("Z2:CN4")
For Each C1 In range1.Cells
'    this will be easy for you to understand
'    str1 = C1.Formula
'    str1 = Replace(str1, "*", "")
'    C1.Formula = str1
     C1.Formula = Replace(C1.Formula, "*", "")
Next
End Sub
 
Upvote 0
modify this to your need. if it helps you pl mark it as a solution for the benefit of future readers of the thread.
VBA Code:
Sub Macro1()
Dim range1 As Range
Set range1 = Range("Z2:CN4")
For Each C1 In range1.Cells
'    this will be easy for you to understand
'    str1 = C1.Formula
'    str1 = Replace(str1, "*", "")
'    C1.Formula = str1
     C1.Formula = Replace(C1.Formula, "*", "")
Next
End Sub
It worked, Thank you.
Your macro was changing (Z4*0.5) to (Z405), removing the *, as it should. So I used ctrl H to change them back, "40" to "4*". Done.
COUNTIFS($L$3:$L$1190,"M-Q-R:V-X:Z-W",$A$3:$A$1190,"W")+(Z4*0.5)
 
Upvote 0
What about this?
I think it should avoid the problem you mentioned and it also does all the replacements at once rather than cell-by-cell.

VBA Code:
Sub Replace_Ast()
    With Range("Z2:CN4")
      .Replace What:="""~*", Replacement:="""", LookAt:=xlPart
      .Replace What:="~*""", Replacement:="""", LookAt:=xlPart
    End With
End Sub
 
Upvote 0
Solution
What about this?
I think it should avoid the problem you mentioned and it also does all the replacements at once rather than cell-by-cell.

VBA Code:
Sub Replace_Ast()
    With Range("Z2:CN4")
      .Replace What:="""~*", Replacement:="""", LookAt:=xlPart
      .Replace What:="~*""", Replacement:="""", LookAt:=xlPart
    End With
End Sub
I've tested and it works!
Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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