#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default SUMIF CODE

What is wrong with this statement it igves "expected end of statement" error
msg.

sub abc()
pos=15
Range(Cells(3, 2), Cells(pos, 2)) = "=SUMIF(A2:A5,"10")"
end sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SUMIF CODE


If you dont want the 10 in quotes then


Code:
--------------------
Range(Cells(3, 2), Cells(pos, 2)).Value = "=SUMIF(A2:A5,10)"

--------------------
however if you do then


Code:
--------------------

Range(Cells(3, 2), Cells(pos, 2)).Value = "=SUMIF(A2:A5," & Chr(34) & "10" & Chr(34) & ")"

--------------------


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=36902

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SUMIF CODE

Double up the double quotes in strings in your VBA code:

Range(Cells(3, 2), Cells(pos, 2)) = "=SUMIF(A2:A5,""10"")"



ezil wrote:

What is wrong with this statement it igves "expected end of statement" error
msg.

sub abc()
pos=15
Range(Cells(3, 2), Cells(pos, 2)) = "=SUMIF(A2:A5,"10")"
end sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SUMIF CODE


Yes Dave, a much smarter approach!


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=36902

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 Calculation in Code Problem Joel Excel Programming 3 April 29th 08 01:49 PM
change SUMIF formula into a vb code ASU Excel Discussion (Misc queries) 1 September 6th 06 07:08 PM
How to simplfy If & Sumif Code Martin Excel Discussion (Misc queries) 1 April 27th 06 10:29 AM
Usage of SUMIF formula in the VBA code GreenInIowa Excel Programming 2 November 1st 05 09:36 PM
Sumif in VB Code Mervyn Thomas Excel Programming 3 January 29th 04 03:47 PM


All times are GMT +1. The time now is 07:50 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"