MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 9th, 2002, 06:31 AM   #1
BenNV
Board Regular
 
Join Date: Mar 2002
Posts: 160
Default

Hello,

I'm trying to apply code currently being used for individual worksheets to the whole workbook. If the worksheet is not active and the below conditions are met, then I get a runtime error. Could you take a look at my code and see what I need to change and where I should put the code:


Private Sub Worksheet_Calculate()

Dim lLastRow As Long, Data1, ColE, ColG, ColH, COlI, lRow As Long
Dim shtThis As Worksheet, bThisRow As Boolean
Dim ranj As String

Data1 = Cells(1, 4).Value

Set shtThis = ActiveSheet

With Cells(5, 1).CurrentRegion
lLastRow = .Rows.Count + .Row - 1
End With


For lRow = 5 To lLastRow
ColE = Cells(lRow, 5).Value
ColF = Cells(lRow, 6).Value
ColG = Cells(lRow, 7).Value
ColH = Cells(lRow, .Value
COlI = Cells(lRow, 9).Value

bThisRow = False 'pay
cThisRow = False 'pay nothing


Select Case ColG
Case "DDD"
If ColH = Data1 Or COlI = Data1 Then _
cThisRow = True
Case "OO"
If ColE = Data1 Then _
bThisRow = True
Case "RRR"
Select Case ColF
Case "X"
If COlI = Data1 Then _
cThisRow = True
Case "O"
If ColH = Data1 Then _
cThisRow = True
End Select
Case "II"
Select Case ColF
Case "X"
If COlI = Data1 Then _
bThisRow = True
Case "O"
If ColH = Data1 Then _
bThisRow = True
End Select
Case "RKK"
Select Case ColF
Case "X"
If ColH = Data1 Then _
bThisRow = True
Case "O"
If COlI = Data1 Then _
bThisRow = True
End Select
Case "BOX"
Select Case ColF
Case "X"
If ColH = Data1 Then _
cThisRow = True
Case "O"
If COlI = Data1 Then _
cThisRow = True
End Select
End Select

With shtThis.Rows(lRow)
If bThisRow Then
'Cells(lRow, 12).Select
Range("A" & lRow & ":L" & lRow).Select
'ranj = "A" & lRow & ":L" & lRow
' Object.Range (ranj)
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With

'Else
' With .Interior
' .ColorIndex = xlNone
' .Pattern = xlNone
' End With
End If

If cThisRow Then
Range("A" & lRow & ":L" & lRow).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End If

End With
Next


End Sub

BenNV is offline   Reply With Quote
Old Apr 9th, 2002, 06:49 AM   #2
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi BenNV


Right click on the Excel icon, top left next to "File", select "View Code" and paste you code in here:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

End Sub
Dave Hawley is offline   Reply With Quote
Old Apr 9th, 2002, 10:18 AM   #3
BenNV
Board Regular
 
Join Date: Mar 2002
Posts: 160
Default

Thank you. I've done that but it appears some of the properties may need to be changed as this does not apply for workbooks. Can you help?
BenNV is offline   Reply With Quote
Old Apr 10th, 2002, 02:12 AM   #4
BenNV
Board Regular
 
Join Date: Mar 2002
Posts: 160
Default

Can anyone help on this, please?

I am trying to make the conditions apply to the whole workbook for each worksheet, even if the worksheet is inactive.

I put the code where Dave suggested but think certain areas of the code need changing.
BenNV is offline   Reply With Quote
Old Apr 10th, 2002, 02:38 AM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Where and what errors are you recieving?
Email your Wb if you want. TsTom@hotmail.com
Tom

[ This Message was edited by: TsTom on 2002-04-10 01:42 ]
Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 04:00 AM   #6
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi Ben
I sent this to the wrong e-mail address and am not sure if yours is correct either.
Anyway,

Try this and see if it solves your problem.
Replace the following lines of code in your Workbook_SheetCalculate event

Replace:
Dim shtThis As Workbook, bThisRow As Boolean
with
Dim shtThis As Worksheet, bThisRow As Boolean

Replace:
Set shtThis = ActiveWorkbook
with
Set shtThis = sh

Let me know if this works.
Thanks,
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 04:24 AM   #7
BenNV
Board Regular
 
Join Date: Mar 2002
Posts: 160
Default

Tom, thanks. But only seems to work for the active sheet, not any of the other inactive sheets, ie. if a sheet is inactive and the conditions meet then nothing happens.
BenNV is offline   Reply With Quote
Old Apr 10th, 2002, 04:40 AM   #8
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

I may be missing your objective here, Ben.
You want all sheets to do what?
I do not know exactly how your workbook functions. Do you want the same process which is occuring in the active sheet to duplicate in every sheet?
If that is the case then that would not be a problem...
Sorry if I missed the mark here.
Let me know,
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 10th, 2002, 04:45 AM   #9
BenNV
Board Regular
 
Join Date: Mar 2002
Posts: 160
Default

Tom, in all of the sheets in the workbook, I need the same process to occur. So say the conditions are met in an inactive worksheet then I need the cells to highlight. At the moment it only works on the active worksheet. So, should the conditions that I specified be met in an inactive worksheet, nothing happens.
BenNV is offline   Reply With Quote
Old Apr 10th, 2002, 04:48 AM   #10
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

If the former is the case then do this:

Replace:
Set shtThis = sh
With:
For Each shtThis In Worksheets

Right above End Sub add this:
Next

This will loop through every sheet in the workbook everytime any sheet calculates.

Tom
Tom Schreiner is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:26 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes