MACRO PROBLEM: How to HardCode SUMIF formula ONLY

cgeorge4

Board Regular
Joined
Jul 24, 2011
Messages
91
Hello,

I use a code to hard code vlookup - but is it possible to hard code cells with SUMIF formula's only?


1) I want to hard code any variety of SUMIF or IF formula on the active worksheet.

2) I want the code to only work on the sheet that is activated.

3) There are other basic formulas (sum, subtraction, multiplication, division...etc) that should be left intact.



I've searched many places for a solution. The closest one had the name of the worksheet included in the code - and that will not work for my project. The worksheet name or tab name should not be a factor.

The code below is the code that I mentioned above, but not using. It refers to a workbook name. I pasted it here in case it might be helpful to you.


Code:
[COLOR=#333333]Sub ReplaceSumIf()[/COLOR]
For Each sht In ActiveWorkbook.Sheets    For Each cll In sht.UsedRange        If cll.Formula Like "*SUMIF*Workbook2*" Then cll.Formula = cll.Value    NextNext [COLOR=#333333]End Sub[/COLOR]


thank you in advance Darlings,

Juicy
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Does this code do what you want...

Code:
Sub ConvertSUMIFtoCellValue()
  Dim Cell As Range
  For Each Cell In Cells.SpecialCells(xlFormulas)
    If InStr(Cell.Formula, "SUMIF(") Then Cell.Value = Cell.Value
  Next
End Sub
 
Upvote 0
Hi there, I'm sorry to say it didn't work. I have formulas starting with IF(OR(....... and SUM(IF(......... Could that be the issue since SUMIF is what is written into the code? Thanks
 
Upvote 0
Hi there, I'm sorry to say it didn't work. I have formulas starting with IF(OR(....... and SUM(IF(......... Could that be the issue since SUMIF is what is written into the code? Thanks
Yes, that is the problem. The reason I used SUMIF and not SUM(IF is because of what you wrote in the title to your thread... there is a SUMIF function which is what I thought you used. Anyway, give this code a try and see if it works for you...

Code:
Sub ConvertSUMIFtoCellValue()
  Dim Cell As Range
  For Each Cell In Cells.SpecialCells(xlFormulas)
    If InStr(Cell.Formula, "SUM(IF(") Then Cell.Value = Cell.Value
  Next
End Sub
 
Upvote 0
:laugh:Hi, sorry i'm responding so late. I had to dig for my new password.

Thank you so much. I did add ( and it worked perfectly.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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