Macro line is red and I don't know why issue

Darkshine31

New Member
Joined
Oct 10, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi good people of the Excel world.

I have a macro that I've built which is designed to "Reset" a sheet back to default settings once a client has had access to it and changed certain cell ranges as required.

I have a range of cells named "data_entry_low_grid_connection_prospects_speel" (which happens to be merged cells C36 - C39 in case you need to know). It has a working formula in it that, if overwritten by the client needs to be reset when the reset button is clicked in the sheet.

The formula is:

=IF(ISNUMBER(SEARCH("Please go", data_entry_low_grid_potential_question)), data_entry_low_grid_potential_question, "Please provide an explanation for low prospects of connection - see example - do not start with a capital letter or end with a full stop")

The macro entry related to that section is:

Range("data_entry_low_grid_connection_prospects_speel").Select
ActiveCell.FormulaR1C1 = "=IF(ISNUMBER(SEARCH("Please go", data_entry_low_grid_potential_question)), data_entry_low_grid_potential_question, "Please provide an explanation for low prospects of connection - see example - do not start with a capital letter or end with a full stop")"
I don't understand why the line is red and doesn't work in VBA when it does work fine in the sheet without the use of VBA.
Any assistance would be much appreciated.
Dean
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hello, the error is due to the quotes inside the formula. They "break" the big quote.

To put quotes into a string, you need to double them (from " to "").

For example

VBA Code:
"=IF(Sheet1!A1=0,"""",Sheet1!A1)"

Is the correct way to write in a VBA string : =IF(Sheet1!A1=0,"",Sheet1!A1)
 
Upvote 0
Solution
Hello, the error is due to the quotes inside the formula. They "break" the big quote.

To put quotes into a string, you need to double them (from " to "").

For example

VBA Code:
"=IF(Sheet1!A1=0,"""",Sheet1!A1)"

Is the correct way to write in a VBA string : =IF(Sheet1!A1=0,"",Sheet1!A1)
Aaaahhh!

Fantastic.

Thank you saboh12617 for your time :)
 
Upvote 0

Forum statistics

Threads
1,225,502
Messages
6,185,345
Members
453,287
Latest member
Emeister

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