Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro in Excel

Status
Not open for further replies.

tjl99a1

IS-IT--Management
Jun 17, 2003
11
0
0
US
I am trying to create a macro in Excel. I need it to copy certain data from a specific row. The row would be based on the last cell with data in a specific column. After I copy each peice of data it gets pasted into another worksheet, then they all get put through a calculation, and I want the results/value pasted in that cell. Here is what i have so far:
Range("D18").Select
Selection.Copy
Windows("LNG_SC_Version_G.xls").Activate
Range("C8").Select
ActiveSheet.Paste
Windows("Review_Àü·Â·®¿ä±Ý.xls").Activate
Range("I18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("LNG_SC_Version_G.xls").Activate
Range("C10").Select
ActiveSheet.Paste
Windows("Review_Àü·Â·®¿ä±Ý.xls").Activate
Range("J18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("LNG_SC_Version_G.xls").Activate
Range("C12").Select
ActiveSheet.Paste
Application.WindowState = xlMinimized
Windows("Review_Àü·Â·®¿ä±Ý.xls").Activate
Range("K18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("LNG_SC_Version_G.xls").Activate
Range("C14").Select
ActiveSheet.Paste
Range("C18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Review_Àü·Â·®¿ä±Ý.xls").Activate
Range("F18").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

When I run it as is it always is the same data from the same rows I know I need to do a findnext or something but dont know how
Thanks
 
Hi,

What about the COPY TO RANGE? How does that change with each pass?
Code:
Sub b()
   Dim wbLNG As Workbook, wbRev As Workbook, lRow As Long
   Set wbLNG = Workbooks("LNG_SC_Version_G.xls")
   Set wbRev = Workbooks("Review_Àü·Â·®¿ä±Ý.xls")
   
   lRow = 18
'this solves the FROM range, but what about the COPY TO RANGE?
'how does that change with each pass???
   With wbRev
      Do While .Cells(lRow, "D").Value <> ""
         .Cells(lRow, "D").Copy wbLNG.Range("C8").Paste
         .Cells(lRow, "I").Copy wbLNG.Range("C10").Paste
         .Cells(lRow, "J").Copy wbLNG.Range("C12").Paste
         .Cells(lRow, "K").Copy wbLNG.Range("C14").Paste
         wbLNG.Range("C18").Copy .Range("F18").PasteSpecial( _
            Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False)
         lRow = lRow + 1
      Loop
   End With
End Sub

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Skip,
The copy to on the LNG never changes, LNG is an overly complicated calc, the copy to on the last part which goes to the Review is what will change and the copied cells are from that same row. I'll try your code and let you know how it worked, thanks alot!!!!
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top