Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default If statement based on cell formatting/style

Hi,

I am wondering if it is possible to do the following.
I have an Excel sheet that is some sort of financial report.
I want to have a function that would go...

If CellFormat = Style1 then "H1"
If CellFormat = Style2 then "H2"
If CellFormat = Style3 then "H3"
If CellFormat = Style4 then "H3"
If CellValue = Total then "TL"
Else the line is "LN"

I'd then extend it to... if LN and (Row value = 0) then hide row.

So it would hide rows if the 'resource code' is 0

The other option is to do it manually but was wondering if it's possible to do it via VBA.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default If statement based on cell formatting/style

Steven North wrote:

I am wondering if it is possible to do the following.
I have an Excel sheet that is some sort of financial report.
I want to have a function that would go...

If CellFormat = Style1 then "H1"
If CellFormat = Style2 then "H2"
If CellFormat = Style3 then "H3"
If CellFormat = Style4 then "H3"
If CellValue = Total then "TL"
Else the line is "LN"

I'd then extend it to... if LN and (Row value = 0) then hide row.

So it would hide rows if the 'resource code' is 0

The other option is to do it manually but was wondering if it's possible
to do it via VBA.


Something like this, perhaps? This assumes you're using Styles; if you're
using individual elements like bolding, fonts, and/or colors, you'll need to
essentially completely rewrite the entire function...

Function blargh(what As Range)
Select Case what.Style
Case Style1
blargh = "H1"
Case Style2
blargh = "H2"
Case Style3
blargh = "H3"
Case Style4
blargh = "H4"
Case Else
If what.Value = "Total" Then
blargh = "TL"
Else
If Application.WorksheetFunction.Sum(what.EntireRow) = 0 _
Then what.EntireRow.Hidden = True
blargh = "LN"
End If
End Select
End Function

--
I'm glad nobody else thought of that first.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default If statement based on cell formatting/style

Cheers for that.
I'll give it a go and see what transpires. It looks promising :)

On Tuesday, October 22, 2013 3:44:55 PM UTC+8, Auric__ wrote:
Steven North wrote:



I am wondering if it is possible to do the following.


I have an Excel sheet that is some sort of financial report.


I want to have a function that would go...




If CellFormat = Style1 then "H1"


If CellFormat = Style2 then "H2"


If CellFormat = Style3 then "H3"


If CellFormat = Style4 then "H3"


If CellValue = Total then "TL"


Else the line is "LN"




I'd then extend it to... if LN and (Row value = 0) then hide row.




So it would hide rows if the 'resource code' is 0




The other option is to do it manually but was wondering if it's possible


to do it via VBA.




Something like this, perhaps? This assumes you're using Styles; if you're

using individual elements like bolding, fonts, and/or colors, you'll need to

essentially completely rewrite the entire function...



Function blargh(what As Range)

Select Case what.Style

Case Style1

blargh = "H1"

Case Style2

blargh = "H2"

Case Style3

blargh = "H3"

Case Style4

blargh = "H4"

Case Else

If what.Value = "Total" Then

blargh = "TL"

Else

If Application.WorksheetFunction.Sum(what.EntireRow) = 0 _

Then what.EntireRow.Hidden = True

blargh = "LN"

End If

End Select

End Function



--

I'm glad nobody else thought of that first.


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
IF Statement based on first two characters of cell PVANS Excel Programming 4 September 28th 09 01:30 PM
style sheets vs cell formatting Exceluser1 Excel Worksheet Functions 0 April 15th 09 02:14 PM
Fomatting a row based on style of a cell within the same row [email protected] Excel Programming 1 December 1st 07 07:07 AM
Conditional formatting based on if statement. kevin Excel Worksheet Functions 2 January 12th 05 03:07 AM


All times are GMT +1. The time now is 10:20 AM.

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"