473,386 Members | 1,969 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.

EXCEL VBA copy paste loop macro

12
Hello,

I need a simple macro to copy range ("I:M") and paste offset(0,5) every time when I click the button.
max 492 times

Thanks in advance for any help
Jan 5 '18 #1
12 6146
NeoPa
32,556 Expert Mod 16PB
When you say it might need to be repeated I find myself confused.
  1. In what way would repeating the action make any sense?
  2. Does the limit specified refer to the number of times the code can be invoked by some trigger or is there some looping required?
    If the latter then what determines the looping?
  3. Does the Offset() you're talking about reference the Range() object mentioned or would this be from Selection (You should appreciate that as a Method, Object() has no meaning unless qualified.)?
Do please try to consider your question fully before posting it.
Jan 5 '18 #2
effosia
12
I need to copy Product Table x492 times.
Every time when clicking the button add next table and add name Z1, Z2,Z3 etc.

In my macro Excel add the copied range once all x492. I want to depend functioning of the macro from the button ADD PRODUCT.
or Combobox list
If sb choose Z1 from the list then will see the table to put the data
If choose Z2 will see the next table to input data for product Z2 etc.

The loop determines clicking on the button Add Product.
Jan 5 '18 #3
effosia
12
I change the macro and now it looks like underneath:

If I click the button ADD PRODUCT it add products one time.
But I want to relate the functioning of the macro to the button.
Everytime when I click the button it will copy and paste range offset(0,5)
and add Z2,Z3,Z4... name in cell Q1(Z1), V1(Z2) etc.

Here is the code:
Expand|Select|Wrap|Line Numbers
Expand|Select|Wrap|Line Numbers
  1.     Sub CopyPaste()
  2.     '
  3.     ' CopyPaste Macro
  4.     '
  5.     Dim i As Long
  6.     For i = 1 To 492
  7.     'Copies the specified selection to the Clipboard
  8.     Range("I:L").Select
  9.     Selection.Copy
  10.     'Paste the specified selection to the specified range
  11.     Range("I1").Offset(0, 5 * i).Select
  12.     ActiveSheet.Paste
  13.     'Unhidde the hidden columns
  14.     Selection.EntireColumn.Hidden = False
  15.     Next i
  16.     'Cancels Cut or Copy mode and removes the moving border
  17.     Application.CutCopyMode = False
  18.     End Sub
  19.  
How to change the code to use by CommandButton.

Everytime when I click the button Add copied range to offset(0,5)
to max 492 times.
Now when I click the button Excel copy and paste range one time (492 times)
Jan 5 '18 #4
NeoPa
32,556 Expert Mod 16PB
I see no answers to my questions in there but I'll look again when I have more time and see if I can work out what you're saying. I expect the code will give me some sort of an understanding.

PS. Each question thread has only one question. Please do not try to add extra questions in here. It makes very little sense anyway as you haven't asked the first in a way that makes sense yet. Jumping forward when we haven't even got started is no way to make progress.
Jan 5 '18 #5
effosia
12
1) User have x492 product and want to add data of each product.
Not to copy and paste product table each time manaly
macro will copy and paste
2) I need trigget (the button) to active the macro each time. Every time when click copy the range with Range("I1").Offset(0, 5 * i)
Max times to click x492
3) Offset reference the Range()
Jan 5 '18 #6
effosia
12
Please for any help as I need it to my assignment, the deadline is 07/01.
Jan 5 '18 #7
GazMathias
228 Expert 128KB
@NeoPa

This question is posted across two active threads. Is there anyway of merging them?

@effosia

I have looked at your spreadsheet and for your single code copy function I feel that you are missing an essential piece of information against your Z entries to signify whether or not they have been been copied to the blue cells.

Please consider adding a column that uses index and match (or equivalent) to track whether or not the value exists in the blue cells. Also consider using a single tracking cell whose job is to return the next number to copy. Look at Excel's Max() function.

You would retrieve this number in the single code copy function and use it to calculate the position of the blue cell to copy the value in to by multiplying it. You seem to be using those kinds of commands already.

You could do this in pure VBA but I feel this approach will help you in the long run as helper columns and tracking cells are essential in more complicated projects in my opinion.

The copy block 492 times you can accomplish by simply thinking about the steps required and going from there. You have most of what you need already.

Gaz
Jan 6 '18 #8
NeoPa
32,556 Expert Mod 16PB
Hi Gaz.

PM me a link to the other and I'll see what I can do.

As this is clearly an assignment, which as we all know is not allowed here, I will make it very clear that posting help is going to be allowed but anyone posting the solution for the OP is likely to have their post deleted and get a warning for breaking the rules.

@Effosia.
I'm not happy that you've made such a poor job of asking the question. I'm even less impressed that you should do so when someone's already provided you with the assignment. I assume whatever you were given to do already made sense. Assignments are not acceptable questions. Asking about a particular concept that you need in your assignment we'll generally help with though. It needs to be asked a lot more clearly than you have done though.

-Adrian (Admin).

PS. @Gaz.
What you've done so far seems perfectly acceptable.
Jan 7 '18 #9
effosia
12
It was a little part of my assignment. Close I found the solution.
Jan 7 '18 #10
NeoPa
32,556 Expert Mod 16PB
Another similar thread was posted as Excel vba problem help!!! (I know, but we have no control over what people use as titles even though there are clear guidelines.

Anyone should feel free to PM me directly if they see that a member has posted what amounts to the same question more than once so I can ensure one is removed before it gets too messy.
Jan 8 '18 #11
effosia
12
Please delete my threads as I found the solution.
Jan 8 '18 #12
NeoPa
32,556 Expert Mod 16PB
That's not how it works Effiosa. Threads typically aren't deleted unless they're a problem. Tidying up yours would be too much work to be worth the effort so they'll stay as they are.
Jan 9 '18 #13

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

Similar topics

3
by: Faith | last post by:
Hello. I need to take a column from Excel(unknown amount of rows) that will be selected by the user and copy those cells. Then I will need to paste those cells into the first column in a Data...
2
by: Mansi | last post by:
I'm trying to automate excel from c#. One of the things I need to do is to copy/paste/insert rows in excel via c# code. I tried to do the following: 1) Select a row in excel (a12 to k12) 2)...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
7
by: VoTiger | last post by:
Hi everyone, i am ttrying to find a way to do the copy / paste between an existing excel file and my flexgrid (in runtime application). But the fact is that i don't know how to proceed. The...
2
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard...
0
by: Nicholas Dreyer | last post by:
Operating System: Microsoft Windows Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) Visual Basic: MIcrosoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 Forms3:...
0
by: six888 | last post by:
i need to make a report using excel. im given a few data in excel document for a 1 month report (1 document for each week). each data document have a few work sheet.i need only certain information in...
2
by: OfficeDummy | last post by:
Hi, everyone! Like I mentioned in the thread title, I need to copy&paste data between different workbooks, and it works fine. However, when the data has been copied to the destination workbook,...
5
by: Jock | last post by:
My purchase order system sequentially added the next number to the new order when I clicked the macro button set up with copy/paste functions and it worked well. I cannot do this now as 2007 does...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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.