Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Excel copay and pasted specifed number of times macro

Posted on 2013-12-02
2
Medium Priority
?
449 Views
Last Modified: 2013-12-02
I need a macro that will look at a range of cells starting in A1 (the number of columns and number of rows will vary each time) and the last column will contain a number.  I need the macro to copy the preceeding columns in each row and paste it in the next worksheet that number of times

Example:
zone1   area    region   5
zone3   area    region   4
zone9   area    region   2
zone8   area    region   1

Will result in:
zone1   area    region
zone1   area    region
zone1   area    region
zone1   area    region
zone1   area    region
zone3   area    region
zone3   area    region
zone3   area    region
zone3   area    region
zone9   area    region
zone9   area    region
zone8   area    region

Again the number of rows and columns will vary but the last column will always include the number of times to copy and paste and the region will start in A1
0
Comment
Question by:djfab99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 39690485
This will clear the contents of the target sheet and copy the new data.
Sub ReptPerLastCol()
    Dim sws As Worksheet
    Dim tws As Worksheet
    Dim sr As Range
    Dim rw As Range
    Set sws = Sheets("Sheet1")
    Set tws = Sheets("Sheet2")
    Set sr = sws.Range("A1").CurrentRegion
    tws.Cells.ClearContents
    For Each rw In sr.Rows
        rw.Resize(, sr.Columns.Count - 1).Copy _
            Sheet2.Range("A" & Sheet2.Range("A" & Rows.Count).End(xlUp).Offset(1).Row).Resize(rw.Cells(1, sr.Columns.Count))
    Next rw
End Sub

Open in new window

0
 

Author Closing Comment

by:djfab99
ID: 39690739
Works Great!  Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question