Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Automatically add Conditional formatting on data/subtotals

Hi All,

I am building an application where l need to add / delete subtotals to
a range of data on a regular basis and l am doing so using VBA. What l
would also like to do is add some conditional formatting to each of
the total rows. Does anybody have any code to do this or point me in
the right direction ? I assume that when removing the subtotals the
rows are deleted and thus the existing conditional formatting. Is this
correct?

All help gratefully appreciated.

TIA

Regareds

Michael beckinsale

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Automatically add Conditional formatting on data/subtotals

Hi

I never did something like that before, but I guess the macro recorder could
give you the first bit of code, from where to start optimizing/changing it.

--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Automatically add Conditional formatting on data/subtotals

Hi Wigi,

Thanks for your response but l have already written the code to
insert / remove subtotals. What l then need to do is automatically
apply conditional formatting to the inserted totals. I could search
the column for partial text (ie *total) and then apply CF to that row/
range but l am hoping for a more efficient / elegant solution.

Regards

Michael Beckinsale

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Automatically add Conditional formatting on data/subtotals

See http://www.xldynamic.com/source/xld.CF.html#subtotal

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"michael.beckinsale" wrote in message
oups.com...
Hi All,

I am building an application where l need to add / delete subtotals to
a range of data on a regular basis and l am doing so using VBA. What l
would also like to do is add some conditional formatting to each of
the total rows. Does anybody have any code to do this or point me in
the right direction ? I assume that when removing the subtotals the
rows are deleted and thus the existing conditional formatting. Is this
correct?

All help gratefully appreciated.

TIA

Regareds

Michael beckinsale



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Automatically add Conditional formatting on data/subtotals

Hi Bob,

Thanks for the link, which shows some useful techniques, but is not
what l am really after. perhaps l did not exlain myself very well.

This is a planning / scheduling application with approx 1000 rows and
100 columns. So to keep the workbook size to a minimum and make the
workbook calculate at an acceptable speed l have kept the use of
formula's (especially nested match / vlookups etc) to a minimum by
using VBA to do 'the donkey work'.

What l really want to do is insert the subtotals using VBA and again
using VBA apply conditional formatting only to the rows which are a
subtotal.

Again l assume that removing subtotals only deletes the subtotal row
and thus the row containing the CF will also be deleted.

Any info / pointers will be really appreciated.

Regards

MB



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Automatically add Conditional formatting on data/subtotals

This should get you started

Sub AddSubtotals()
Dim iLastRow As Long
Dim oCell As Range

With ActiveSheet
.Columns("A:B").RemoveSubtotal
.Columns("A:B").Subtotal GroupBy:=1, _
Function:=xlSum, _
TotalList:=Array(2), _
Replace:=True, _
PageBreaks:=False, _
SummaryBelowData:=True
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set oCell = .Columns(1).Find("Total", LookIn:=xlValues)
If Not oCell Is Nothing Then
Do
oCell.Resize(1, 2).Interior.ColorIndex = 35
Set oCell = oCell.Offset(1, 0).Resize(iLastRow - oCell.Row +
1, 1).Find("*Total*", LookIn:=xlValues)
Loop While Not oCell Is Nothing
End If
End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"michael.beckinsale" wrote in message
ups.com...
Hi Bob,

Thanks for the link, which shows some useful techniques, but is not
what l am really after. perhaps l did not exlain myself very well.

This is a planning / scheduling application with approx 1000 rows and
100 columns. So to keep the workbook size to a minimum and make the
workbook calculate at an acceptable speed l have kept the use of
formula's (especially nested match / vlookups etc) to a minimum by
using VBA to do 'the donkey work'.

What l really want to do is insert the subtotals using VBA and again
using VBA apply conditional formatting only to the rows which are a
subtotal.

Again l assume that removing subtotals only deletes the subtotal row
and thus the row containing the CF will also be deleted.

Any info / pointers will be really appreciated.

Regards

MB



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Automatically add Conditional formatting on data/subtotals

Hi Bob,

Many thanks for the example code. I have not tested it yet but should
this:

Set oCell = .Columns(1).Find("Total", LookIn:=xlValues)

really be this:

Set oCell = .Columns(1).Find(*Total*, LookIn:=xlValues)

ie change " to *

Regards

MB

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Automatically add Conditional formatting on data/subtotals

No it is not necessary. There is another argument to Find, LookAt This can
be one of the following XlLookAt constants: xlWhole or xlPart. You could add
that argument to the Find statements, but I think it defaults anyway,
certainly worked in my tests.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"michael.beckinsale" wrote in message
ups.com...
Hi Bob,

Many thanks for the example code. I have not tested it yet but should
this:

Set oCell = .Columns(1).Find("Total", LookIn:=xlValues)

really be this:

Set oCell = .Columns(1).Find(*Total*, LookIn:=xlValues)

ie change " to *

Regards

MB



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
Excel 2003: Conditional Formatting with Subtotals oceanmist Excel Discussion (Misc queries) 1 November 27th 07 09:47 PM
Subtotals & Conditional Formatting Part 2 Studebaker Excel Worksheet Functions 1 May 17th 07 09:19 AM
Subtotals and Conditional Formatting Studebaker Excel Worksheet Functions 1 May 15th 07 06:16 AM
Conditional Formatting and Subtotals Mary Ann Excel Discussion (Misc queries) 2 August 10th 05 12:09 PM
How do I use conditional formatting to change subtotals row format Ken Peterson Excel Worksheet Functions 3 March 24th 05 04:58 PM


All times are GMT +1. The time now is 05:41 PM.

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

About Us

"It's about Microsoft Excel"