ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error in entering a formula (https://www.excelbanter.com/excel-programming/389904-error-entering-formula.html)

Shilps[_2_]

Error in entering a formula
 
Hi,

I am trying to create an array formula through VBA code. I want the formula(
for a particular parameter) to appear like this in Excel
{=SUM(IF(Q9:Q11<"Rejected",I9:I11,0))}

The code is this
Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & "Rejected" & ",I9:I" &
(RowIndex - 1) & ",0))"
Dsheet.Range(tmp).FormulaArray = Fml

This code makes it look like =SUM(IF(Q9:Q11<Rejected,I9:I11,0)) [ Rejected
without quotes and hence gives error #NAME?

If I change the VBA code to

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & ' "Rejected" ' & ",I9:I" &
(RowIndex - 1) & ",0))"

OR

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & " 'Rejected' " & ",I9:I" &
(RowIndex - 1) & ",0))"

it gives error.

I dnt understand what is the problem with quotes!

TIA

Norman Jones

Error in entering a formula
 
Hi Ships,

See Bob Phillips response in your earlier thread.

Bob has shown you hoe to enter an array formula.


---
Regards,
Norman


"Shilps" wrote in message
...
Hi,

I am trying to create an array formula through VBA code. I want the
formula(
for a particular parameter) to appear like this in Excel
{=SUM(IF(Q9:Q11<"Rejected",I9:I11,0))}

The code is this
Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & "Rejected" & ",I9:I" &
(RowIndex - 1) & ",0))"
Dsheet.Range(tmp).FormulaArray = Fml

This code makes it look like =SUM(IF(Q9:Q11<Rejected,I9:I11,0)) [
Rejected
without quotes and hence gives error #NAME?

If I change the VBA code to

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & ' "Rejected" ' & ",I9:I" &
(RowIndex - 1) & ",0))"

OR

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & " 'Rejected' " & ",I9:I" &
(RowIndex - 1) & ",0))"

it gives error.

I dnt understand what is the problem with quotes!

TIA




Shilps[_2_]

Error in entering a formula
 
Didn't help :(

"Norman Jones" wrote:

Hi Ships,

See Bob Phillips response in your earlier thread.

Bob has shown you hoe to enter an array formula.


---
Regards,
Norman


"Shilps" wrote in message
...
Hi,

I am trying to create an array formula through VBA code. I want the
formula(
for a particular parameter) to appear like this in Excel
{=SUM(IF(Q9:Q11<"Rejected",I9:I11,0))}

The code is this
Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & "Rejected" & ",I9:I" &
(RowIndex - 1) & ",0))"
Dsheet.Range(tmp).FormulaArray = Fml

This code makes it look like =SUM(IF(Q9:Q11<Rejected,I9:I11,0)) [
Rejected
without quotes and hence gives error #NAME?

If I change the VBA code to

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & ' "Rejected" ' & ",I9:I" &
(RowIndex - 1) & ",0))"

OR

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & " 'Rejected' " & ",I9:I" &
(RowIndex - 1) & ",0))"

it gives error.

I dnt understand what is the problem with quotes!

TIA





Norman Jones

Error in entering a formula
 
Hi Ships,

'-----------------
See Bob Phillips response in your earlier thread.


Bob has shown you hoe to enter an array formula.


Didn't help :(

'-----------------

Then the polite (and most efficient) course of action
would be to post an explantory response in that thread.

Personally, I find that Bob's reponses are invariably
extremely useful


---
Regards,
Norman



NickHK

Error in entering a formula
 
Works for me.
Maybe a bit more explanation on your part would help you to a solution.

NickHK

"Shilps" wrote in message
...
Didn't help :(

"Norman Jones" wrote:

Hi Ships,

See Bob Phillips response in your earlier thread.

Bob has shown you hoe to enter an array formula.


---
Regards,
Norman


"Shilps" wrote in message
...
Hi,

I am trying to create an array formula through VBA code. I want the
formula(
for a particular parameter) to appear like this in Excel
{=SUM(IF(Q9:Q11<"Rejected",I9:I11,0))}

The code is this
Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & "Rejected" & ",I9:I" &
(RowIndex - 1) & ",0))"
Dsheet.Range(tmp).FormulaArray = Fml

This code makes it look like =SUM(IF(Q9:Q11<Rejected,I9:I11,0)) [
Rejected
without quotes and hence gives error #NAME?

If I change the VBA code to

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & ' "Rejected" ' &

",I9:I" &
(RowIndex - 1) & ",0))"

OR

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & " 'Rejected' " &

",I9:I" &
(RowIndex - 1) & ",0))"

it gives error.

I dnt understand what is the problem with quotes!

TIA







Dave Peterson

Error in entering a formula
 
You could use =sumif():

Option Explicit
Sub testme()
Dim RowIndex As Long
Dim myCell As Range

With ActiveSheet
Set myCell = .Range("a1") 'something
RowIndex = 32 'something
myCell.Formula _
= "=sumif(q9:q1" & RowIndex - 1 _
& ",""<""&""Rejected"",i9:i" & RowIndex - 1 & ")"
End With
End Sub

Shilps wrote:

Hi,

I am trying to create an array formula through VBA code. I want the formula(
for a particular parameter) to appear like this in Excel
{=SUM(IF(Q9:Q11<"Rejected",I9:I11,0))}

The code is this
Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & "Rejected" & ",I9:I" &
(RowIndex - 1) & ",0))"
Dsheet.Range(tmp).FormulaArray = Fml

This code makes it look like =SUM(IF(Q9:Q11<Rejected,I9:I11,0)) [ Rejected
without quotes and hence gives error #NAME?

If I change the VBA code to

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & ' "Rejected" ' & ",I9:I" &
(RowIndex - 1) & ",0))"

OR

Fml = "=SUM(IF(Q9:Q" & (RowIndex - 1) & "<" & " 'Rejected' " & ",I9:I" &
(RowIndex - 1) & ",0))"

it gives error.

I dnt understand what is the problem with quotes!

TIA


--

Dave Peterson


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com