Whats wrong with my code?

KateA

New Member
Joined
Jun 24, 2014
Messages
6
Hi,
I'm compiling a master spreadsheet that pulls values from about 75 other sheets.
I made a mistake and dont want to fix it cell by cell, so ive been trying to learn how to write a macro (trying and failing). Here's what is in the cells of the range concerned;

=SUM(IF((SOURCESHEETX!D20:D40="VAT Gtee")*(SOURCESHEETX!H20:H40="EUR"),SOURCESHEETX!L20:L40,0))+SUM(IF((SOURCESHEETX!D20:D40="VRT Gtee")*(SOURCESHEETX!H20:H40="EUR"),SOURCESHEETX!L20:L40,0))+SUM(IF((SOURCESHEETX!D20:D40="Performance Gtee")*(SOURCESHEETX!H20:H40="EUR"),SOURCESHEETX!L20:L40,0))+SUM(IF((SOURCESHEETX!D20:D40="Gtee")*(SOURCESHEETX!H20:H40="EUR"),SOURCESHEETX!L20:L40,0))+SUM(IF((SOURCESHEETX!D20:D40="Performance Guarantee")*(SOURCESHEETX!H20:H40="EUR"),SOURCESHEETX!L20:L40,0))+SUM(IF((SOURCESHEETX!D20:D40="Letter of Credit")*(SOURCESHEETX!H20:H40="EUR"),SOURCESHEETX!L20:L40,0))

The value for SourceSheetX changes for each cell in the column.
Ive been trying to replace "Gtee" with "C&E Gtee", but the macro I write just keeps deleting everything in the range...(help!)

Here it is

Sub FixMistake ()

OriginalText = MyCell.Value<o:p></o:p>
CorrectedText = Replace(OriginalText, "Gtee", "C&E Gtee", 310, 1)<o:p></o:p>
For Each MyCell In Range("R27:R80")<o:p></o:p>
MyCell.Value = CorrectedText<o:p></o:p>
Next MyCell<o:p></o:p>
End Sub

Whats wrong? Any help would be great. Thanks a mill!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Instead of Value try using Formula.
Code:
Sub FixMistake ()
    For Each MyCell In Range("R27:R80")
        OriginalText = MyCell.Formula
        CorrectedText = Replace(OriginalText, "Gtee", "C&E Gtee", 310, 1)
        MyCell.Formula = CorrectedText
    Next MyCell
End Sub
 
Upvote 0
Instead of Value try using Formula.
Code:
Sub FixMistake ()
    For Each MyCell In Range("R27:R80")
        OriginalText = MyCell.Formula
        CorrectedText = Replace(OriginalText, "Gtee", "C&E Gtee", 310, 1)
        MyCell.Formula = CorrectedText
    Next MyCell
End Sub


A message box flashed up, displaying Run Time Error '1004': Application Defined or Object Defined error.
I forgot to mention that the formula I'm using needs to be entered as an array. Does that change anything?
Thank you so much for your time!
 
Upvote 0
Try using
Code:
MyCell.FormulaArray
, the code is unable to tell if the formula you want to enter into a cell is an array one or not.
 
Upvote 0
Now the message box is telling me I'm 'unable to set the FormulaArray property of the range class. Any solutions?

Again thanks a million!
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

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