LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Calling macros, looping function? Can this code be written more efficiently?

This is my first attempt at vba programming, so I'm sure there are some
obvious flaws in my code below. I'd appreciate your help.

I have a workbook with multiple worksheets. On the first worksheet,
one of the lines asks "Does the unit sell internationally?" followed by
a Yes/No drop-down box.

The goal is to hide unnecessary rows in various worksheets in the
workbook if the unit doesn't sell internationally. If the dropdown is
Yes, then it calls the "Show" macro. If the dropdown is No, then it
calls the "Hide" macro.

Issue 1: I have this first routine stored within the "Sheet1", the
worksheet that contains the cell value being tested. Running the
following code, I'm actually getting a pop-up box listing all of the
macros in the workbook... so I'm assuming that's an error. Do you see
anything obviously wrong with this code?

Private Sub Worksheet_Change(ByVal Target As Range)
' Checks to see if worksheet "Sheet1" cell D20 has changed
' Cell D20 is a Yes/No dropdown box to indicate if unit sells
internationally.
If Not Application.Intersect(Worksheets("Sheet1").Range(" D20"),
Target) Is Nothing Then
' If I-1 cell D20 has changed, then show foreign rows if value of
D20 is "Yes"
' Hide foreign rows if value of D20 is "No"
If Target.Value = "No" Then
Run "Hideforeign"
Else: Run "ShowForeign"
End If
End If
End Sub



Issue 2: Here are the Show/Hide macros. Can this be written more
efficiently?

Sub HideForeign()
'
' HideForeign Macro
' Hides all items in workbook pertaining to foreign activities
'
'
Application.ScreenUpdating = False

Sheets("Sheet1").Range("a33").EntireRow.Hidden = True

Sheets("Sheet2").Range("a30,a31,a42,a43,a47,a50"). EntireRow.Hidden =
True
Sheets("Sheet3").Range("a22").EntireRow.Hidden = True
' There are another 15 sheets with various rows to hide

Application.ScreenUpdating = True
End Sub

Sub ShowForeign()
'
' ShowForeign Macro
' Shows all items in workbook pertaining to foreign activities
'
'
Application.ScreenUpdating = False

Sheets("Sheet1").Range("a33").EntireRow.Hidden = False

Sheets("Sheet2").Range("a30,a31,a42,a43,a47,a50"). EntireRow.Hidden =
False
Sheets("Sheet3").Range("a22").EntireRow.Hidden = False
' Again, another 15 sheets with EntireRow.Hidden set to False.

Application.ScreenUpdating = True
End Sub


Thanks, group!

 
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
Macros written in UK not working in US Teresa Excel Discussion (Misc queries) 1 April 19th 07 06:59 PM
Looping macros using VB code accessuser1308 Excel Discussion (Misc queries) 2 March 9th 05 11:11 PM
Help on writing code more efficiently (Loops) Kathryn[_5_] Excel Programming 3 May 25th 04 08:45 PM
Calling Match function from code Backslider Excel Programming 2 February 28th 04 03:12 AM
Calling Excel FUNCTION MACROS Programmatically from VB Rob Bovey Excel Programming 0 July 23rd 03 09:35 PM


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