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
|