Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 22nd, 2007, 10:31 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Repeating a script or command

I'm new and know virtually nothing about programming.

Here is what I have and what I want. I have a raw data spreadsheet that has data in column F only. My data represents 7 animals recorded for 61 minutes over 5 days, so that's 2135 cells in column F. I want to copy and paste this data from my raw data spreadsheet to my template spreadsheet that analyzes the data. The template is organized by animal and day, so sheet 1 column B (A is the label) represents animal 1 on day 1. Sheet 2 column B represents animal 1 on day 2 up to sheet 5 and day 5. On each sheet column C represents animal 2, etc up to animal 7. So again, I have "vertical" data that needs to be parsed out to multiple sheets and columns.

OK, I have figured out how to do this part and recorded a macro and then edited it to my satisfaction. Here is a snippet of what I have.

Sub CopyPaste()
'
' CopyPaste Macro
' Macro recorded 5/21/2007 by Jack Jones
'

'
    Range("F3:F63").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("B2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F64:F124").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("C2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F125:F185").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("D2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F186:F246").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("E2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F247:F307").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("F2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F308:F368").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("G2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F369:F429").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Range("H2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F430:F490").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Sheets("Day 2Raw").Select
    Range("B2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F491:F551").Select
    Selection.Copy

As you can hopefully see, it copies from column F of RawData and pastes in column B or C, etc of the template. My problem is that this macro only works for 7 animals for 61 minutes over 5 days. There will be times where I want 8, 10, 12 animals and maybe I'll only need to record data for 20 minutes. This wouuld obviously not work for the macro I have created here without rewriting it (I don't want to do that). Here's where I need your help. IF (hopefully I got everything) this code here

Windows("RawData.xls").Activate
    Range("F430:F490").Select
    Selection.Copy
    Windows(" TemplateSens.xls").Activate
    Sheets("Day 2Raw").Select
    Range("B2").Select
    ActiveSheet.Paste
    Windows("RawData.xls").Activate
    Range("F491:F551").Select
    Selection.Copy

represents a "unit" that is a copy and paste "unit", then I assume I could just have a macro repeat this unit however many times I want it to. Assuming this is correct, I would then run into the problem of it just copying and pasting the same thing over and over, which is NOT want I want. So I assume there would be a way to tell the macro to repeat the unit AND let it know to move progressively throught the raw data and the template worksheet, such that the data representing animal 3 on day 2 goes into worksheet 2 column D where it belongs and everything else ends up where it needs to be. I would also want to be able to tell the macro unit to copy and paste 61 cells one time and then 20 times if I needed that another time. I assume that could be a variable that I could manipulate in the macro.

So, to sum up I want to repeat the copy and paste "unit" a variable (of my choosing)number of times while it "moves" through the data and be able to vary the number of cells I move. I hope my question is clear. If you respond, first thank you very much for your time, and secondly please write your response as if you were writing it for an 8 year old. Explain everything and assume I know nothing. I hope that isn't too demanding and again thank you for any help you can offer. OH and if you know of a good, simple tutorial for visual basic geared towards someone who knows nothing about programming, I would be much obliged if you would tell me about it.
Matt






Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating data ph0neman Classic ASP Basics 5 January 18th, 2008 12:34 PM
Repeating Region DynaCube Classic ASP Basics 0 January 12th, 2007 11:26 PM
command for running script in ns2.26 newbie06 Assembly Language 0 October 2nd, 2006 10:23 PM
Repeating Records Nicky_uk Classic ASP Databases 7 February 2nd, 2005 05:41 PM
13. how can i execute a php script using command l phpsharma BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 October 31st, 2003 05:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.