I have worked extensively with Pivot Tables, etc in Excel (97version). But, the closest I have gotten to VB is using the "record" feature.
I now have a neat little Macro that performs several steps. But I need to be able to loop it until all the "assignment s" have been completed. I presume there is some simple feature to call up the Macro that I now have, and execute it until all the assignments have been made, stopping when the "To be Assigned" is zero?
If someone could write me out a simple command to launch, and stop my Macro it would be greatly appreciated.
Thanks for any help anyone can give me.
6 25405 sashi 1,754
Recognized Expert Top Contributor
Hi there,
pls refer to below sample code segment.. take care..
for loop.. -
For index=start to end[Step step]
-
[statements]
-
[Exit For]
-
[statements]
-
Next[index]
-
example usage of for loop -
Dim d As Integer
-
For d = 0 To 2
-
System.Console.WriteLine("In the For Loop")
-
Next d
-
while loop.. -
While condition
-
[statements]
-
End While
-
example usage of while loop.. -
Dim d, e As Integer
-
d = 0
-
e = 6
-
While e > 4
-
e -= 1
-
d += 1
-
End While
-
Debug.Print("The Loop ran " & e & "times")
-
do loop.. -
Do[{while | Until} condition]
-
[statements]
-
[Exit Do]
-
[statements]
-
Loop
-
example usage of do loop.. -
Dim str As String
-
Do Until str = "Cool"
-
System.Console.WriteLine("What to do?")
-
str = System.Console.ReadLine()
-
Loop
-
I found similar code in a book yesterday, but I have failed at the posting. What I am trying to do is to have the Macro stop when the value in a cell reaches zero. That is, there is no one left to assign a dining spot to. I think I need to know how to reference the cell value, if it possible to do so from the Macro. Here is what I have tried, and got a syntax error message.
Sub Macro1_test_DoL oop()
'
' Macro1 Macro
' Macro recorded 8/6/2006
'
' The following is a "Recorded" Macro, which does work independently.
'
Application.Run "'NC - Table Assignments Calculations.xl s'!Assign_Diner s"
'
' The following cell will be at zero when the required cycles have been run.
'
x = [NC - Table Assignments Calculations.xl s]Table Compute!$R$8
Do Until x = 0
Loop
Msg Box x
End
End Sub
If anyone can offer a suggestion it would be appreciated. I am totally new at this, so I have no idea what is supposed to come first, or if I can even do it the way I am trying. Thanks.
Thank you sashi for the code!
'i believe this is what you want.
'<cell value> is your "value in a cell"
do
if <cell value> = 0 then exit do
'<your macro loops here>
loop
it will go round and round until cell value = 0
also (more efficeintly) writen as:
do until <cell value> = 0
'<your macro loops here>
loop
'i believe this is what you want.
'<cell value> is your "value in a cell"
do
if <cell value> = 0 then exit do
'<your macro loops here>
loop
it will go round and round until cell value = 0
also (more efficeintly) writen as:
do until <cell value> = 0
'<your macro loops here>
loop
Thank you BSOB.
I have tried creating a simple exercise to test the Loop. The loop should stop when the cell value reaches zero. When I run the Macro, the steps work, but the "do until" does not recognize the "zero" when it is actually computed. Therefore, I have to shut the operation down. Amazingly though, if I hardcode the zero, the loop stops as desired. The "test" code follows. Maybe someone will have an idea. Thanks.
-----------------------------------------------------------------------------
Sub Test_Loop()
'
' Test_Loop Macro
' Macro recorded 8/8/2006
'
' Go to ActiveCell.Valu e which should become zero:
Sheets("Control Sheet").Select
Range("F2").Sel ect
' Do Until test:
Do Until ActiveCell.Valu e = 0
ActiveCell.Sele ct
' Now to execute Macro:
Sheets("Piv-Summary").Selec t
ActiveSheet.Piv otTables("Pivot Table2").PivotS elect "", xlDataOnly
ActiveSheet.Piv otTables("Pivot Table2").Refres hTable
Sheets("Pivot-detail").Select
Rows("3:3").Sel ect
Selection.Copy
Sheets("Assigne d").Select
Rows("100:100") .Select
Selection.Paste Special Paste:=xlValues , Operation:=xlNo ne, SkipBlanks:= _
False, Transpose:=Fals e
' Sort
Columns("A: D").Select
Selection.Sort Key1:=Range("B2 "), Order1:=xlAscen ding, Header:=xlGuess , _
OrderCustom:=1, MatchCase:=Fals e, Orientation:=xl TopToBottom
' position cursor:
Range("c2").Sel ect
' End of recorded Macro
Loop
End Sub
I finally got it to work by going back to the "ActiveCell " at the end of the Macro as well as at the start. Maybe there is a better way, but it worked for me.
Thanks to all you who offered suggestions.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tom |
last post by:
A question for gui application programmers. . .
I 've got some GUI programs, written in Python/wxPython, and I've got
a help button and a help menu item. Also, I've got a compiled file
made with the microsoft HTML workshop utility, lets call it
c:\path\help.chm. My question is how do you launch it from the GUI?
What logic do I put behind the "help" button, in other words.
I thought it would be
os.spawnv(os.P_DETACH,...
|
by: Sarir Khamsi |
last post by:
Is there a way to get help the way you get it from the Python
interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the
module cmd.Cmd? I know how to add commands and help text to cmd.Cmd
but I would also like to get the man-page-like help for classes and
functions. Does anyone know how to do that? Thanks.
Sarir
|
by: Sudheer Kareem |
last post by:
Dear All
Please tell me how to assosiate help files with my Vb.net
Project.
Regards
Sudheer
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing result in any way. Who can
help me, I thank you very very much.
list.cpp(main program)
//--------------------------------------------------------------------------
-
#pragma hdrstop
#pragma argsused
|
by: d.warnermurray |
last post by:
I am doing a project for school that involves creating help files for a html
authoring tool.
If you could help me with answers to some questions it would really help.
1. What tasks do you expect an html authoring tool to help you accomplish?
2. What do you expect from online help for a html authoring tool?
3. What audience do you think a freeware html authoring tool is directed
towards?
| |
by: Craig Keightley |
last post by:
Please help, i have attached my page which worksin IE but i cannnot get the
drop down menu to fucntion in firefox. Any one have any ideas why?
Many Thanks
Craig
<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>
<html>
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With numarray, help gives unhelpful responses:
|
by: Steve |
last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp
My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable
In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
|
by: Mark |
last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my
home computer has an abbreviated help screen not 2% of the help on my laptop.
All the settings look the same on both including search the internet for
help, but the help is worthless. Any ideas?
|
by: hitencontractor |
last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003.
I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About.
The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar,
FILE EDIT VIEW INSERT ... HELP.
I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help.
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |