Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2008, 12:37 AM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help!!!!!Private Sub Worksheet_Change

Can someone help me!!!!!!!! Please!!!!!!!!! am a visual basic novice and am trying to building a calculator in excel using the “Worksheet_Change” code but unfortunately its not working properly. So, am seeking some advice…………

What I want:

• The code to perform is an automatic update once a cell has changes.
Lets say when H3=Renewals,
Hide some cells and go to H3 and don’t run the code again unless I type something other than Renewals
It should also let me continue working with the worksheet cells (That’s my main problem the code runs over and over and over again and it doesn’t let me continue)

The code that am using is:

Private Sub Worksheet_Change(ByVal Target As Range)

* First action I want the code to perform

If Range("H3") = "RENEWALS" Then
Range("b37").Select
Sheets("COVER PAGE").Select
Rows("37:43").Select
Selection.EntireRow.Hidden = True
Range("h3").Select
Else
Rows("37:43").Select
Selection.EntireRow.Hidden = False
Range("D7").Select
End If

* Code should stop here and let the user continue till the next if statement

If Range("M26") = "Yes" Then
Range("b76").Select
Sheets("COVER PAGE").Select
Rows("76:77").Select
Selection.EntireRow.Hidden = False
Range("D30").Select

Else
Rows("76:77").Select
Selection.EntireRow.Hidden = True
Range("D30").Select

End If
* Code should stop here and let the user continue till the next if statement

If Range("M24") = "REVISED" Then
Range("a55").Select
Sheets("COVER PAGE").Select
Rows("50:57").Select
Selection.EntireRow.Hidden = False
Rows("55:56").Select
Selection.EntireRow.Hidden = True
Rows("60:66").Select
Selection.EntireRow.Hidden = True

Range("d52").Select

End If

* Code should stop here and let the user continue till the next if statement

'PRINEW SUPER CALCULATIONS
If Range("M24") = "NEW" Then
Range("a52").Select
Sheets("COVER PAGE").Select
Rows("50:57").Select
Selection.EntireRow.Hidden = False
'Hide Row
Rows("53:54").Select
Selection.EntireRow.Hidden = True
'Hide
Rows("60:66").Select
Selection.EntireRow.Hidden = True

' SELECT CELLS AFTER HIDE....
Sheets("COVER PAGE").Select
Range("d52").Select

End If
* Code should stop here and let the user continue till the next if statement

'VICSUPER CALCULATIONS
If Range("M24") = "OTHER(Eg VICSUPER" Then
Range("A62").Select
Sheets("COVER PAGE").Select

Rows("51:66").Select
Selection.EntireRow.Hidden = False
' Hide
Sheets("COVER PAGE").Select
Rows("51:56").Select
Selection.EntireRow.Hidden = True

' SELECT CELLS AFTER HIDE....
Sheets("COVER PAGE").Select
'Range("E62").Select

End If

* Code should stop here and let the user continue till the next if statement

'SERB SUPER CALCULATIONS
If Range("M24") = "SERB" Then
Sheets("COVER PAGE").Select
Rows("50:57").Select
Selection.EntireRow.Hidden = False
'Hide
Rows("51:56").Select
Selection.EntireRow.Hidden = True
'Hide
Rows("60:66").Select
Selection.EntireRow.Hidden = True

' SELECT CELLS AFTER HIDE....
Sheets("COVER PAGE").Select
Range("c80").Select

End If
* Code should stop here and let the user continue till the next if statement

End Sub


 
Old March 6th, 2008, 10:35 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

VicM

If your intention 'Code should stop here and let the user continue till the next if statement' is to have code wait for the user's input is impossible. The code will get executed sequentially and will allow user interaction only if it executed.

There are couple of workarounds:

1) Have the If's nested to your application logic. So on one execution, it will check all available paths

2) Have 'Exit Sub' statment, if you want to exit from that part and allow the user to continue (type more info)



http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Messages ViagraFalls BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 October 22nd, 2007 03:48 PM
Worksheet_Change executing selectively lfrench Excel VBA 3 April 3rd, 2007 03:59 PM
Excel Worksheet_Change option mtowle Excel VBA 1 October 21st, 2005 09:27 AM
Using Private Sub cutovoi Excel VBA 0 February 5th, 2004 12:55 PM
How to step into Worksheet_Change Piblon Excel VBA 2 December 17th, 2003 04:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.