VBA replacing a formula with a macro returns #Value (Wrong data type)

silent3486

New Member
Joined
May 14, 2013
Messages
3
I have an excel macro that copies a tab from the previous month, renames it to the correct month, and replaces the formulas with the correct month/formula. The issue I ran into is that when it replaces the formula with the correct month, it returns #Value and says "wrong data type".

I believe that the issue is that I am replacing a formula that has underlying data with a text string. The replacement macro is below:

<!-- BEGIN TEMPLATE: bbcode_code -->
Code:
 ' This replaces all formulas with the correct monthApplication.DisplayAlerts = False Worksheets(nmonth + " " + iYear).Cells.Replace What:=lmonth + " " + iYear, Replacement:=nmonth + " " + nYear, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=True, _ ReplaceFormat:=False Application.DisplayAlerts = True

<!-- END TEMPLATE: bbcode_code -->The formula that this replaces is:

<!-- BEGIN TEMPLATE: bbcode_code -->
Code:
=COUNTIF( 'Mar 2013 details'!E2:E299,"support")

<!-- END TEMPLATE: bbcode_code -->Does anyone know how to use VBA to replace text in a formula as well as the underlying data?​
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Also, iYear = 2013, lmonth = Mar, nmonth = Apr, nYear = 2013 unless lmonth is Dec, then it is 2014
Basically, it replaces "Mar 2013" with "Apr 2013" in the formula
It does replace the text in the formula but the cell says it is wrong data type.

The macro replaces this:
=COUNTIF( 'Mar 2013 details'!E2:E299,"support")

With this:
=COUNTIF( 'Apr 2013 details'!E2:E299,"support")​
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

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