Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Operator is in excel cells, how to reference it

Hi, All:


What I want to accomplish is that I want to summarize the data in the
sheets "data" under some conditions?

For example I want to know how many customers have balance below 4000
and how many of them have balance above 5000, etc

So I have a set of conditions in column B in "summary" sheet, < 4000,

5000


in column C, another variable =0, =1 etc

...........

In column O, is the sum of customers satisfy my conditions in column B
to P.

So I have B2="'< 4000," B3="5000".......

How can I reference them in VBA, for example, I want to check if
Sheets("data").cells(1,1)0
or not. I want to use B2 directly. How can I do that in VBA
I tried

if Sheets("data").cells(1,1) & Sheets("summary").(2, 2) then
..........
end if

It doesn't work. Any one knows how to handle this? Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Operator is in excel cells, how to reference it

You can access worksheet functions from VBA as follows

MyTotal = worksheetfunctions.sum("A1:B10")

what is also nice is that any range in VBA can also be passed to the
worksheet functions

set MyRange = sheets("Sheet5").Range("B11:C12")
MyTotal = worksheetfunctions.sum(MyRange)

The range can also be a name from the worksheets
MyTotal = worksheetfunctions.sum(activesheet.MyRange)

You probably want to use the worksheet function SUMIF.
set MyRange = sheets("Sheet5").Range("A11:A100")
lesstotal = worksheetfunctions. _
sumif(MyRange,"'< 4000",MyRange.offset(rowoffset:=0,columnoffset:=1)
sheets("Summary").Range("B1") = lesstotal


Another method is for VBA to actuall put the formula for sumif into tyour
summary worksheet
lesstotalformula = "=sumif(Sheet5!A11:A100,""<4000"",Sheet5!B11:B100) "
sheets("Summary").Range("B1").formula = lesstotalformula

the above can be made dynamic as follows

LastRow = 100
lesstotalformula = "=sumif(Sheet5!A11:A" & Lastrow & _
",""<4000"",Sheet5!B11:B" & LastRow & ")"
sheets("Summary").Range("B1").formula = lesstotalformula


" wrote:

Hi, All:


What I want to accomplish is that I want to summarize the data in the
sheets "data" under some conditions?

For example I want to know how many customers have balance below 4000
and how many of them have balance above 5000, etc

So I have a set of conditions in column B in "summary" sheet, < 4000,

5000


in column C, another variable =0, =1 etc

...........

In column O, is the sum of customers satisfy my conditions in column B
to P.

So I have B2="'< 4000," B3="5000".......

How can I reference them in VBA, for example, I want to check if
Sheets("data").cells(1,1)0
or not. I want to use B2 directly. How can I do that in VBA
I tried

if Sheets("data").cells(1,1) & Sheets("summary").(2, 2) then
..........
end if

It doesn't work. Any one knows how to handle this? Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Operator is in excel cells, how to reference it

You might try looking at Advanced Filter. In the cell above your balances
enter "Balances" for one of the columns in your List range.

For your Criteria range, in say F1 & G1 enter "Balances" in both cells
F2: <5000
G3: 6000

Note not in same rows for 'Or' conditions.

See this excellent introduction to Advanced Filters by Debra Dalgleish
http://www.contextures.com/xladvfilter01.html

Try recording a macro

Regards
Peter T


wrote in message
ups.com...
Hi, All:


What I want to accomplish is that I want to summarize the data in the
sheets "data" under some conditions?

For example I want to know how many customers have balance below 4000
and how many of them have balance above 5000, etc

So I have a set of conditions in column B in "summary" sheet, < 4000,

5000


in column C, another variable =0, =1 etc

..........

In column O, is the sum of customers satisfy my conditions in column B
to P.

So I have B2="'< 4000," B3="5000".......

How can I reference them in VBA, for example, I want to check if
Sheets("data").cells(1,1)0
or not. I want to use B2 directly. How can I do that in VBA
I tried

if Sheets("data").cells(1,1) & Sheets("summary").(2, 2) then
.........
end if

It doesn't work. Any one knows how to handle this? Thanks.



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
Using cell reference with logical operator in DGET expression BoxleyFarm Excel Worksheet Functions 1 April 28th 10 11:31 AM
How to use union reference operator? JoeU2004 Excel Discussion (Misc queries) 4 May 18th 09 04:37 PM
Reference an Operator from a cell with Sumproduct deeds Excel Worksheet Functions 4 April 25th 08 04:06 PM
Why doesnt union reference operator work with COUNTIF? joeu2004 Excel Discussion (Misc queries) 1 September 15th 07 09:59 AM
How to use a cell value as operator in a worksheet reference? JRP2003 Excel Worksheet Functions 2 August 14th 06 06:24 PM


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