473,511 Members | 15,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need a basic VB loop

2 New Member
Hi all, I'm in over my head.

The middle part below ( My recorded macro) works fine, but I'd like some help making it loop. can you help?

Expand|Select|Wrap|Line Numbers
  1. For each office (name1, name2,  name3 ...)
  2.  
  3. Sheets("MA").Select
  4.     ActiveWindow.SmallScroll Down:=-15
  5.     Selection.AutoFilter Field:=6, Criteria1:="name"
  6.     ActiveWindow.SmallScroll Down:=-42
  7.     Range("A2:e1178").Select
  8.     Selection.Copy
  9.     Sheets("name").Select
  10.     Rows("2:2").Select
  11.     Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
  12.     ActiveSheet.Paste
  13.     ActiveWindow.SmallScroll Down:=-18
  14.     Sheets("MA").Select
  15.     Range(Selection, Cells(1)).Select
  16.     Selection.AutoFilter Field:=6
  17.     Range("A2").Select
  18.     Application.CutCopyMode = False
  19.  
  20. next office
and I don't know how to do a loop.

thanks in advance
Mar 16 '07 #1
1 1302
Killer42
8,435 Recognized Expert Expert
I think a lot would depend on where these names are coming from. If it is a set list that you just want to hard-code here, then a couple of techniques come to mind.
  • One would be to put them in an array, then use a FOR loop to traverse the array (you use the loop counter as the index into the array).
  • Another fairly simple (though slightly ugly) method would be to place the bulk of your code in another Sub and invoke it with each name in turn. For example:
    DoMyStuff "Name1"
    DoMyStuff "Name2"
    And so on.
Mar 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2408
by: Barnes | last post by:
Hi, Can anyone please tell me how I can use the replace method to replace a character if it occures in more than one textbox without having to write separate function for each textbox. The...
56
4045
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
16
9286
by: Neal | last post by:
Hi, I saw the VB6 Code to do this at this link: http://www.dotnet247.com/247reference/msgs/11/56581.aspx The VB6 Code reads as follows: Private Type Rect Left As Long
1
1081
by: Q | last post by:
Hello you all, I have to create an application which writes data to a serial port, waits for an answer and read this answer from the same serial port. I just don't know where to start. Any...
16
4161
by: C++ Hell | last post by:
Hey everyone just designing a quiz for school and managed to write the code for the questions and answers thou i have to add scores and at the end an overall score does anyone have any idea what to...
7
2516
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
0
2044
by: Cause | last post by:
In the following code to call my website for serial registration reasons, I want to test on localhost. The code works on the internet, but this code sends me a bunch of 400 bad request errors when I...
5
1889
by: swtstrawberry | last post by:
All the basic stuff I get like cin/cout...but the interpolation formula, the for/while loop, and reading in the desired altitude...i dont get it....please help...anybody here are the directions I...
2
1512
by: kristopher.erickson | last post by:
Hereis some basic code that works fine: For Each itm In fld.Items I = I + 1 j = 1 Set rng = wks.Cells(I, j) If itm.Start <"" Then rng.Value = itm.Start j = j + 1
2
3266
by: alxasa | last post by:
Hi, I have a setInterval which executes its command every 10 seconds in a infinite loop. I've got something real basic like: var processes=0; function startme(){ if(stopthisloop>1)
0
7137
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...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
jinu1996
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...
1
7074
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...
0
5659
agi2029
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,...
1
5063
isladogs
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...
0
4734
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...
0
1572
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 ...
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.