Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default VBA Filtered Subtotal - require sheet activation?

Hi all - I am trying to assign the sum and number of filtered results
to variables per below after filtering..

// FILTER ALLOCS SHEET
Sheets("Allocs").Range("A1").AutoFilter Field:=4, Criteria1:=TapsRic
Sheets("Allocs").Range("A1").AutoFilter Field:=5, Criteria1:=TapsDir

//ASSIGN SUBTOTAL VALUES TO VARIABLES
AllocsCount =
Sheets("Allocs").Application.WorksheetFunction.Sub total(3,
Range("G:G")) - 1
AllocsSum = Sheets("Allocs").Application.WorksheetFunction.Sub total(9,
Range("G:G"))

Now this works fine if I activate the "Allocs" sheet prior to running
those last 2 lines - however, as it is in a loop and it goes through
hundreds of lines it results in the screen flickering between 2 sheets
which is annoying. Is there anyway that I can achieve the same without
activating the sheet? It seems that the two variables when I MsgBox
them are the sum and number of rows on the other sheet that i want
active the whole time.

Thanks for any help
Will

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default VBA Filtered Subtotal - require sheet activation?

Activation may be required, select rarely is, but to keep from seeing it
happen use :
Application.ScreenUpdating = False
'Do some fancy code
Application.ScreenUpdating = True

Mike F

wrote in message
oups.com...
Hi all - I am trying to assign the sum and number of filtered results
to variables per below after filtering..

// FILTER ALLOCS SHEET
Sheets("Allocs").Range("A1").AutoFilter Field:=4, Criteria1:=TapsRic
Sheets("Allocs").Range("A1").AutoFilter Field:=5, Criteria1:=TapsDir

//ASSIGN SUBTOTAL VALUES TO VARIABLES
AllocsCount =
Sheets("Allocs").Application.WorksheetFunction.Sub total(3,
Range("G:G")) - 1
AllocsSum = Sheets("Allocs").Application.WorksheetFunction.Sub total(9,
Range("G:G"))

Now this works fine if I activate the "Allocs" sheet prior to running
those last 2 lines - however, as it is in a loop and it goes through
hundreds of lines it results in the screen flickering between 2 sheets
which is annoying. Is there anyway that I can achieve the same without
activating the sheet? It seems that the two variables when I MsgBox
them are the sum and number of rows on the other sheet that i want
active the whole time.

Thanks for any help
Will



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA Filtered Subtotal - require sheet activation?

Range("G:G") is unqualified. In most cases, it'll refer to the active sheet.

You could use:

AllocsCount = Application.Subtotal(3, Worksheets("Allocs").Range("G:G")) - 1

so that you're more specific.

" wrote:

Hi all - I am trying to assign the sum and number of filtered results
to variables per below after filtering..

// FILTER ALLOCS SHEET
Sheets("Allocs").Range("A1").AutoFilter Field:=4, Criteria1:=TapsRic
Sheets("Allocs").Range("A1").AutoFilter Field:=5, Criteria1:=TapsDir

//ASSIGN SUBTOTAL VALUES TO VARIABLES
AllocsCount =
Sheets("Allocs").Application.WorksheetFunction.Sub total(3,
Range("G:G")) - 1
AllocsSum = Sheets("Allocs").Application.WorksheetFunction.Sub total(9,
Range("G:G"))

Now this works fine if I activate the "Allocs" sheet prior to running
those last 2 lines - however, as it is in a loop and it goes through
hundreds of lines it results in the screen flickering between 2 sheets
which is annoying. Is there anyway that I can achieve the same without
activating the sheet? It seems that the two variables when I MsgBox
them are the sum and number of rows on the other sheet that i want
active the whole time.

Thanks for any help
Will


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default VBA Filtered Subtotal - require sheet activation?

Wonderful - both methods solved the problem but since I would like to
see progress on the other worksheet I have gone with the 2nd method.
Cheers guys

On Jan 27, 3:27 pm, Dave Peterson wrote:
Range("G:G") is unqualified. In most cases, it'll refer to the active sheet.

You could use:

AllocsCount = Application.Subtotal(3, Worksheets("Allocs").Range("G:G")) - 1

so that you're more specific.



" wrote:

Hi all - I am trying to assign the sum and number of filtered results
to variables per below after filtering..


// FILTER ALLOCS SHEET
Sheets("Allocs").Range("A1").AutoFilter Field:=4, Criteria1:=TapsRic
Sheets("Allocs").Range("A1").AutoFilter Field:=5, Criteria1:=TapsDir


//ASSIGN SUBTOTAL VALUES TO VARIABLES
AllocsCount =
Sheets("Allocs").Application.WorksheetFunction.Sub total(3,
Range("G:G")) - 1
AllocsSum = Sheets("Allocs").Application.WorksheetFunction.Sub total(9,
Range("G:G"))


Now this works fine if I activate the "Allocs" sheet prior to running
those last 2 lines - however, as it is in a loop and it goes through
hundreds of lines it results in the screen flickering between 2 sheets
which is annoying. Is there anyway that I can achieve the same without
activating the sheet? It seems that the two variables when I MsgBox
them are the sum and number of rows on the other sheet that i want
active the whole time.


Thanks for any help
Will--


Dave Peterson


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
Sheet activation CWillis Excel Discussion (Misc queries) 5 June 1st 06 09:50 PM
How do I insert a filtered subtotal into overall summary Mel Excel Discussion (Misc queries) 3 May 29th 06 03:33 PM
Changing the activation of a sheet that is unactive and undefined Andyjk1 Excel Programming 3 April 20th 06 06:29 PM
macro on Sheet activation [email protected] Excel Programming 3 August 29th 05 12:36 AM
Sheet protection error msg - Unrequested sheet activation deltree[_3_] Excel Programming 0 January 28th 04 06:20 PM


All times are GMT +1. The time now is 06:15 AM.

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"