I am working on a sheet where I need to export cells B7, B9, E9, B13, F18, F20:F22, F24, F30, F32:F34, and H34 into another workbook where the data will be copied into the next empty row (all on one row). I am then linking this function to a "Submit" button.
I can do most of this my simply recording a macro, but I cannot figure out how to search for an empty row and paste. I am sure there is a way to copy those cells with one command as well, but I have not been able to figure out the syntax, so each copy/paste operation has its own line. The code I have so far is:
Sub Macro3()
'
' Macro3 Macro
'
'
Workbooks.Open Filename:= _
"C:\Documents and Settings\mjewell\My Documents\TestTargetSheet.xlsx"
Windows("TestSourceSheet.xlsm").Activate
Range("B7").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("A1").Select
ActiveSheet.Paste
Windows("TestSourceSheet.xlsm").Activate
Range("B9").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("B1").Select
ActiveSheet.Paste
Windows("TestSourceSheet.xlsm").Activate
Range("B13").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("C1").Select
ActiveSheet.Paste
Windows("TestSourceSheet.xlsm").Activate
Range("E9").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("D1").Select
ActiveSheet.Paste
Windows("TestSourceSheet.xlsm").Activate
Range("E13").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("E1").Select
ActiveSheet.Paste
Windows("TestSourceSheet.xlsm").Activate
Range("F18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("F1").Select
ActiveSheet.Paste
Windows("TestSourceSheet.xlsm").Activate
Range("F20:F22").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("G1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Windows("TestSourceSheet.xlsm").Activate
Range("F24:F30").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("J1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Windows("TestSourceSheet.xlsm").Activate
Range("F32:F33").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("Q1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Windows("TestSourceSheet.xlsm").Activate
Range("I7:J13").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TestTargetSheet.xlsx").Activate
Range("S1").Select
Range("S1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
If anyone doesnt mind showing me how to consolidate this code as well as paste to the next open row, I would really appreciate that. Since I want to learn how to do this better I would also appreciate any comments in your code that you would be willing to make so I can follow it easier.
Thanks!
Bookmarks