For-Next/Cells Syntax help

jsolomon

Board Regular
Joined
Mar 25, 2005
Messages
109
Hi guys,
I am still trying to grasp the for-each-next logic, but it seems that I am sttill having trouble. The code I am trying to write this time will take the text in rows 16-60 & cols a-h on sheet-Invoice and copy it to the log worksheet. Here is my code. Any help is greatly appreciated.
Code:
      For SourceRow = 16 To 60
          Set SourceRange = ActiveWorkbook.Sheets("invoice").Range("Cells(SourceRow,1):Cells(SourceRow,8)")
          ActiveWorkbook.Sheets("log").Range("a1").Value = SourceRange
     Next SourceRow

Thanks,

Joe
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Barrie Davidson

MrExcel MVP
Joined
Feb 10, 2002
Messages
2,330
How about?
Code:
For SourceRow = 16 To 60
    Set SourceRange = ActiveWorkbook.Sheets("invoice").Range(Cells(SourceRow, 1), Cells(SourceRow, 8))
    SourceRange.Copy _
        Destination:=ActiveWorkbook.Sheets("log").Range("a" + SourceRow - 15)
Next SourceRow
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,061
Office Version
  1. 365
Platform
  1. Windows
Joe

Are you sure you need a loop here?
Code:
ActiveWorkbook.Sheets("invoice").Range("A16:H60").Copy
ActiveWorkbook.Sheets("log").Range("a1").PasteSpecial xlPasteValues
 

jsolomon

Board Regular
Joined
Mar 25, 2005
Messages
109
well i was going to put in an if statement becasue some of the rows may be blank.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,680
Messages
5,573,624
Members
412,539
Latest member
itchy00
Top