+ Reply to Thread
Results 1 to 4 of 4

Macro for calculate, copy, paste loop

Hybrid View

  1. #1
    Registered User
    Join Date
    10-12-2008
    Location
    London
    Posts
    7

    Macro for calculate, copy, paste loop

    Hi all,

    I have a spreadsheet with input data from a large number of cases, referred to as ID numbers. For each ID, I have multiple data points on several variables. For each ID, I then compute scores on each of the variables, by taking sums, averages, etc. across all the values for each ID.

    In my spreadsheet, I calculate scores for one ID number at a time. This is done by placing an ID number in a “reference” cell. All the formulas that calculate variable scores then refer to the reference cell to determine which ID number to calculate the variable scores for. When I have calculated variable values for one ID, I can copy these values, and paste (paste values) to an “output” spreadsheet tab. I then move on to entering a new ID in the reference cell.

    What I need to do is to be able to automate the process of entering an ID number in the reference cell, and copying/pasting the results from the calculation formulas into the “output” tab. The functionality I am aiming for is to have to two cells where I specify the range of ID numbers to loop through. The routine would then run through the calculation/copy/paste steps for all ID numbers between the first specified ID number and the second specified ID number.

    I have attached a spreadsheet file that illustrates the process. Note that the attached spreadsheet is a simplified version of the much more complex spreadsheet I am using. The structure is the same, however.

    I am very hopeful that this would be quite easy to achieve with a simple VB loop function, combined with a copy-paste/special function. Unfortunately, I am very new to VB and macros, so this challenge is beyond my current skill level. I would therefore be extremely grateful for any help, tips, or assistance with this!

    Many thanks!

    S
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Perhaps like this?
    Sub x()
    
    Dim i As Long
    
    With Sheets("Calculation & controls")
        For i = .Range("J6") To .Range("J7")
            .Range("J1") = i
            Sheets("Output").Cells(Rows.Count, 1).End(xlUp)(2).Resize(, 4) = .Range("A7").Resize(, 4).Value
        Next i
    End With
    
    End Sub

  3. #3
    Registered User
    Join Date
    10-12-2008
    Location
    London
    Posts
    7

    Solved

    Yes, this does exactly what I was looking for. Thanks very much!!!

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by stevenf View Post
    Yes, this does exactly what I was looking for. Thanks very much!!!
    Please mark the question solved.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. copy, paste, sort, macro
    By d0wnt0wn in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2008, 04:11 PM
  2. Automated copy paste using macro
    By Qppg in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-28-2008, 04:39 PM
  3. Copy and paste variables using a macro
    By Nigel in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 06-11-2008, 11:13 PM
  4. copy and paste value using macro
    By shilpz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2008, 06:31 PM
  5. macro to copy and paste data to end of data in second column
    By nancy2002f in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-03-2007, 05:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1