VBA Formula with Quotations

EMcK01

Board Regular
Joined
Jun 14, 2015
Messages
87
Hi,

I'm sure this is a silly one but I can't figure it out. I'm wanting to add the following formula using my macro:
Code:
=IF(OR(C8>=6,D8>=6),"Strength","")
When I convert that into my script it looks like this:

Code:
Cells(r, 6).Formula = ("=IF(OR(" & Cells(r, 3).Address & ">=6," & Cells(r, 4).Address & ">=6)," & ""Strength"," & """" & ")")
However its giving me an issue around the word strength. I'm sure its associated with the quotation marks but these are required for the formula to work and I can't seem to re-work it generate the formula correctly.

Thanks,
EMcK
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,270
Office Version
365
Platform
Windows
How about
Code:
Cells(r, 6).FormulaR1C1 = "=IF(OR(rc3>=6,rc4>=6),""Strength"","""")"
But you you are using a loop to insert the formula over a range of rows there is no need.
 

EMcK01

Board Regular
Joined
Jun 14, 2015
Messages
87
Thanks for the reply, while that works I should of noted the row number is dynamic so the IF formula changes as it moves down the sheet.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,270
Office Version
365
Platform
Windows
The row number is dynamic in that formula, but if you are putting the formula into every row via a loop you don't need to.
 

EMcK01

Board Regular
Joined
Jun 14, 2015
Messages
87
Thanks for your reply again Fluff. I was trying to do so via a loop but this isn't working for me, what am doing wrong? Not every row requires formula so I can't do a copy down.
 

EMcK01

Board Regular
Joined
Jun 14, 2015
Messages
87
Sorry Fluff, user error on my end when I thought it wasn't working. It was working perfectly well.
Thanks, EMcK
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,270
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback.
If not every cell needs the formula, then you will probably need a loop.
 

Forum statistics

Threads
1,082,131
Messages
5,363,337
Members
400,726
Latest member
Shahzad Taimoor

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top