473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

help for macro looping in excel

3
i have this code that needs to be loop nth time..

Expand|Select|Wrap|Line Numbers
  1. Sub Macro12()
  2. '
  3. ' Macro12 Macro
  4. '
  5.  
  6. '
  7.     Range("A2:D6").Select
  8.     Application.CutCopyMode = False
  9.     Selection.Copy
  10.     Range("E2").Select
  11.     ActiveSheet.Paste
  12.     Range("A7:D11").Select
  13.     Application.CutCopyMode = False
  14.     Selection.Copy
  15.     Range("E7").Select
  16.     ActiveSheet.Paste
  17.     Range("E15").Select
  18. End Sub
  19.  
im a newbie in VB so dont know how to change the value of A2:D6 to increment to 5.. so it will be A7:D11 for the next loop. as well as where to paste E2 to E7.
Feb 28 '13 #1
8 1395
Rabbit
12,516 Expert Mod 8TB
It looks like you already have the two ranges in your code. Although it doesn't make sense why you would split it when you can just do it in one go by using A2:D11.
Feb 28 '13 #2
zmbd
5,501 Expert Mod 4TB
do a search on relative cell address in VBA by opening the VBA editor to your code and press [F1] there is was a nice example in the [F1] files that will show you step by step.
Let us know if that isn't available to you.
Feb 28 '13 #3
monmon
3
its just actually copy A2:A6 then paste to B2. then copy A7:A11 then copy to B7. I just posted the two ranges to let the helper know the range from which the next loop would be.
Feb 28 '13 #4
zmbd
5,501 Expert Mod 4TB
That's fine,
You still need to use the relative cell address with offset for movement.
Feb 28 '13 #5
Rabbit
12,516 Expert Mod 8TB
What I'm trying to say is that copying A2:A6 and then copying A7:A11 is the same thing as just copying A2:A11.
Feb 28 '13 #6
monmon
3
nope.. because in the first range.. you have to paste it in b2.. second in b7
Mar 1 '13 #7
Rabbit
12,516 Expert Mod 8TB
It's the same thing. Copying A2:A11 and pasting it into B2 is the exact same result as copying A2:A6, pasting into B2, then copying A7:A11, and pasting into B7.
Mar 1 '13 #8
zmbd
5,501 Expert Mod 4TB
monmon:
Look, what we're getting at is that:
What you are doing within the code that you've already posted simply needs to be repeated.
I've told you to look-up "relative cell addressing" and the "Offset" method.
There is also in Excel VBA a direct method of selecting and pasting selected cells.
All of these methods are easily found by opening your VBA-Editor and searching help.
What you will not get here is a complete code .
Mar 1 '13 #9

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

Similar topics

1
by: Bon | last post by:
Hello all I create a form with three buttons in MS Access 2000. They are Open Excel Template, Save Draft and Save Final. When I click the Open Excel Template button, the Excel template will be...
0
by: Nizar000 | last post by:
HI, CAN ANYONE HELP ME TO OPEN A FILE WITH EXCEL MACRO WRITTEN IN VISUAL BASIC, WITHOUT SPECIFING IT'S PATH ? MY TXT FILE IS IN THE SAME PLACE WITH THE EXCEL FILE. THE COMMAND : OPEN...
1
newnewbie
by: newnewbie | last post by:
Every week I get an Excel file that needs to be modified to be imported in Access. Modification includes columns renaming, deleting some of them, changing their order and data type, etc. I...
8
by: Briansmi1116 | last post by:
Hi all, I am using Access 2003 as well as Excel 2003. I have an Access database that has an output to Excel button I created. This outputs a form to an Excel file A. I then have Excel...
0
by: Jason Huang | last post by:
Hi, In my C# 1.1 windows form Form1, I would like to open an existing Excel file EX1.xls and run the Macro M1 in the EX1.xls. I can open the EX1.xls with no problem, but I encounterd some...
8
by: jotr | last post by:
I need a lot of help because I have never created a macro before. I am trying to set up a macro that will search column BV rows 5-1004 of my spreadsheet for a number. When found I want the data...
2
by: jotr | last post by:
I recently received help writing a search macro for excel, but now I am trying to change it up to use it in another spreadsheet, and I am having some troubles. I need it to search two cells one has...
1
by: mmurphmsu | last post by:
I am working on a VBA macro in Excel that will copy a sheet move it and then rename it based on what the user enters in a pop up box. Here is my code for the module: frmShow.Show ...
1
by: zwheeler | last post by:
I am trying to run an access macro from an excel application. i found the following code and tried to implement it but i keep getting a error 2046: i go to references and set the references to :...
0
by: Michael mealin | last post by:
Hi guys. I am trying to fuly automate a cut and paste operation. Basically the data is dragged off the net, formatted using a macro in word then copied from word and pasted into Excel. From there...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.