Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default skip actions within a macro if a cell value is zero

Hi All
(app is excel 2003)
I have a worksheet showing 9 weeks of data in rows (19:149) and columns (A:K).

I'm filtering and splits this data into weekly reports on their own
worksheets.

I've addressed each week of data separately within the macro so formulas
could change to lookup different data. Here's what the macro is currently
doing:

- copy the base worksheet (sheet 1)
- Advance filter for a specific week nominated via a Vlookup formula
- delete unwanted rows through deleting hidden rows
- update formulas to show information relevant to this week only (sourced
from totals data calculated on another worksheet)
- format the sheet (delete unnecessary buttons etc).

I'd like to add a check before running each section of the macro..

i.e. before copying the base worksheet (sheet 1), check that the total for
this new week is greater than zero (total value is in sheet2.cell("C101")).
otherwise
don't run this part of the macro (don't create the worksheet for this week)
- skip to the next section of the macro which will create a worksheet for
week 2 (after again checking that weeks total in Sheet2.cell("D101") is
greater than zero)
and so on through the macro..

Not sure if this is possible???

--
Thank for your help
BeSmart

example of code (sorry I'm a novice and I know my code is clumsy and not the
most effecient - but I'm self-taught and learning as I go...)
_____________________
Sub Split_Weeks()
Dim cell As Range
Dim myCell As Range
Set r = ActiveSheet.Range("A19:A148")
nLastRow = r.Rows.Count + r.Row - 1

.....
'''' code to create Week 1 starts here ''''
Sheets("Sheet 1").Select
Sheets("Sheet1").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "MBA" & " " & Sheets("Sheet2").Range("A8").Value
Range("B18").Select
ActiveCell.FormulaR1C1 = "=""=""&Sheet2!R[-10]C[-1]"
ActiveSheet.Range("A19:K148").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Range("B17:B18"), Unique:=False
For n = nLastRow To 1 Step -1
If Cells(n, "A").EntireRow.Hidden = True Then
Rows(n).Delete
End If
Next
ActiveSheet.ShowAllData
Range("E18").ClearContents ''(this section is formatting)''
ActiveSheet.Shapes("planned").Select
Selection.Delete
ActiveSheet.Shapes("week_list").Select
Selection.Delete
Range("G11").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP("" ""&MID(R[7]C[-5],3,10),WEEKS,2,FALSE)"
Range("G12").Select
'''' code to create Week 8 starts here '''''
Sheets("Sheet 1").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "MBA" & " " & Sheets("Sheet2").Range("A9").Value
Range("B18").Select
ActiveCell.FormulaR1C1 = "=""=""&Sheet2!R[-9]C[-1]"
Range("B19").Select
ActiveSheet.Range("A19:K148").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Range("B17:B18"), Unique:=False
For n = nLastRow To 1 Step -1
If Cells(n, "A").EntireRow.Hidden = True Then
Rows(n).Delete
End If
Next
ActiveSheet.ShowAllData
Range("E18").ClearContents
ActiveSheet.Shapes("planned").Select
Selection.Delete
ActiveSheet.Shapes("week_list").Select
Selection.Delete
Range("G11").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP("" ""&MID(R[7]C[-5],3,10),WEEKS,2,FALSE)"
Range("G12").Select
.....
--
Thank for your help
BeSmart
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default skip actions within a macro if a cell value is zero

In general you can loop through a range (in your case C101, D101 etc)
checking a value to decide to run a subroutine. Example shown

Dim rngCheck as Range, rngC as Range
Set rngCheck = Sheet2.Range("C101:K101)
For each rngC in rngCheck
If rngC.Value 0 then
Call YourSubroutine to run here
Else
'do something else if required
End If
Next

You might find that if you partition your code into sub routines it will be
a lot easier to write and modify.

Also within you code there is no need to select data and then act on it.
e.g.

ActiveSheet.Shapes("planned").Select
Selection.Delete

If far more efficient to use: ActiveSheet.Shapes("planned").Delete

Since you might not want or need to select a sheet or cell etc. before you
act on it use:
Sheets("Sheet1").Shapes("planned").Delete


--

Regards,
Nigel




"BeSmart" wrote in message
...
Hi All
(app is excel 2003)
I have a worksheet showing 9 weeks of data in rows (19:149) and columns
(A:K).

I'm filtering and splits this data into weekly reports on their own
worksheets.

I've addressed each week of data separately within the macro so formulas
could change to lookup different data. Here's what the macro is currently
doing:

- copy the base worksheet (sheet 1)
- Advance filter for a specific week nominated via a Vlookup formula
- delete unwanted rows through deleting hidden rows
- update formulas to show information relevant to this week only (sourced
from totals data calculated on another worksheet)
- format the sheet (delete unnecessary buttons etc).

I'd like to add a check before running each section of the macro..

i.e. before copying the base worksheet (sheet 1), check that the total for
this new week is greater than zero (total value is in
sheet2.cell("C101")).
otherwise
don't run this part of the macro (don't create the worksheet for this
week)
- skip to the next section of the macro which will create a worksheet for
week 2 (after again checking that weeks total in Sheet2.cell("D101") is
greater than zero)
and so on through the macro..

Not sure if this is possible???

--
Thank for your help
BeSmart

example of code (sorry I'm a novice and I know my code is clumsy and not
the
most effecient - but I'm self-taught and learning as I go...)
_____________________
Sub Split_Weeks()
Dim cell As Range
Dim myCell As Range
Set r = ActiveSheet.Range("A19:A148")
nLastRow = r.Rows.Count + r.Row - 1

....
'''' code to create Week 1 starts here ''''
Sheets("Sheet 1").Select
Sheets("Sheet1").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "MBA" & " " & Sheets("Sheet2").Range("A8").Value
Range("B18").Select
ActiveCell.FormulaR1C1 = "=""=""&Sheet2!R[-10]C[-1]"
ActiveSheet.Range("A19:K148").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Range("B17:B18"), Unique:=False
For n = nLastRow To 1 Step -1
If Cells(n, "A").EntireRow.Hidden = True Then
Rows(n).Delete
End If
Next
ActiveSheet.ShowAllData
Range("E18").ClearContents ''(this section is formatting)''
ActiveSheet.Shapes("planned").Select
Selection.Delete
ActiveSheet.Shapes("week_list").Select
Selection.Delete
Range("G11").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(""
""&MID(R[7]C[-5],3,10),WEEKS,2,FALSE)"
Range("G12").Select
'''' code to create Week 8 starts here '''''
Sheets("Sheet 1").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "MBA" & " " & Sheets("Sheet2").Range("A9").Value
Range("B18").Select
ActiveCell.FormulaR1C1 = "=""=""&Sheet2!R[-9]C[-1]"
Range("B19").Select
ActiveSheet.Range("A19:K148").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:= _
Range("B17:B18"), Unique:=False
For n = nLastRow To 1 Step -1
If Cells(n, "A").EntireRow.Hidden = True Then
Rows(n).Delete
End If
Next
ActiveSheet.ShowAllData
Range("E18").ClearContents
ActiveSheet.Shapes("planned").Select
Selection.Delete
ActiveSheet.Shapes("week_list").Select
Selection.Delete
Range("G11").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(""
""&MID(R[7]C[-5],3,10),WEEKS,2,FALSE)"
Range("G12").Select
....
--
Thank for your help
BeSmart


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
MACRO PASTE CELL to COLUMN, SKIP ROWS Dan Excel Discussion (Misc queries) 1 February 2nd 10 01:03 PM
Hide Macro Actions FrankTimJr Excel Programming 3 June 4th 07 06:02 PM
Hide actions while macro executes Ben Rum Excel Programming 2 December 1st 06 09:19 PM
If cell is empty then run macro otherwise skip this macro [email protected] Excel Programming 3 June 12th 06 03:55 PM
How do I skip a blank cell within macro? DJ Dusty[_6_] Excel Programming 3 March 20th 06 11:17 PM


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