Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SUMIF not working when used in VBA

When I use the workbooks.range.formular1c1 object in VBA, the formula's do
not calculate and instead show #NAME? as the value. I can edit each cell and
then press ENTER to get the values to update, but is there a way to get the
values to show as soon as the code completes?

The VBA statement is

worksheet.Range("B2").FormulaR1C1 = "=sumif(sheet1!A:A,rc[-1],sheet1!D:D)"

to sum all the rows in column D of sheet1 where the column A row = the value
in cell A2 on the current sheet. There is no problem with the formula
itself, since just selecting the cell and pressing F2 and ENTER updates the
value.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default SUMIF not working when used in VBA

maybe turn calculation to automatic and make sure the cell isn't formatted as
Text.

--
Regards,
Tom Ogilvy


"spud" wrote:

When I use the workbooks.range.formular1c1 object in VBA, the formula's do
not calculate and instead show #NAME? as the value. I can edit each cell and
then press ENTER to get the values to update, but is there a way to get the
values to show as soon as the code completes?

The VBA statement is

worksheet.Range("B2").FormulaR1C1 = "=sumif(sheet1!A:A,rc[-1],sheet1!D:D)"

to sum all the rows in column D of sheet1 where the column A row = the value
in cell A2 on the current sheet. There is no problem with the formula
itself, since just selecting the cell and pressing F2 and ENTER updates the
value.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SUMIF not working when used in VBA

Tom - thanks. I used calculation both ways, and formatted the cells as 0.00
number format in the macro but the problem persists.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default SUMIF not working when used in VBA

You are mixing reference types (A1 vs R1C1) in your formula.
Use A1 type only in the "Formula" property.
Use R1C1 type only in the "FormulaR1C1" property.
--
Festina Lente


"spud" wrote:

When I use the workbooks.range.formular1c1 object in VBA, the formula's do
not calculate and instead show #NAME? as the value. I can edit each cell and
then press ENTER to get the values to update, but is there a way to get the
values to show as soon as the code completes?

The VBA statement is

worksheet.Range("B2").FormulaR1C1 = "=sumif(sheet1!A:A,rc[-1],sheet1!D:D)"

to sum all the rows in column D of sheet1 where the column A row = the value
in cell A2 on the current sheet. There is no problem with the formula
itself, since just selecting the cell and pressing F2 and ENTER updates the
value.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default SUMIF not working when used in VBA

As PAPADOS discerningly observed (and I overlooked), you are mixing your form
of addressing.

worksheet.Range("B2").FormulaR1C1 = "=sumif(sheet1!A:A,rc[-1],sheet1!D:D)"

should be

worksheet.Range("B2").FormulaR1C1 = "=sumif(sheet1!C1,rc[-1],sheet1!C4)"

--
Regards,
Tom Ogilvy



"spud" wrote:

Tom - thanks. I used calculation both ways, and formatted the cells as 0.00
number format in the macro but the problem persists.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SUMIF Formula not working TonyK Excel Discussion (Misc queries) 1 February 15th 10 04:39 PM
SUMIF no longer working Monish Excel Worksheet Functions 4 February 2nd 09 04:47 AM
SUMIF not working #VALUE! Scorpvin Excel Worksheet Functions 1 September 29th 05 11:18 PM
SUMIF function not working CarFreek Excel Worksheet Functions 11 August 25th 05 02:45 AM
SumIF is not working DanVDM Excel Worksheet Functions 3 July 18th 05 04:07 PM


All times are GMT +1. The time now is 07:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"