+ Reply to Thread
Results 1 to 3 of 3

Offset Troubles

Hybrid View

Mclark8750 Offset Troubles 03-18-2019, 07:34 PM
6StringJazzer Re: Offset Troubles 03-18-2019, 08:07 PM
romperstomper Re: Offset Troubles 03-19-2019, 04:13 AM
  1. #1
    Registered User
    Join Date
    03-18-2019
    Location
    Rancho Cucamonga, Ca.
    MS-Off Ver
    Office 365
    Posts
    1

    Offset Troubles

    Good afternoon all,

    I am having an issue with how the offset is working in my module and I am looking for a little help or insight into what I am doing wrong. Here is the code that I have written. But when I run the module all it does is stacks everything on to the 2nd row and it won't offset each row like I am intending?

    CopyColumnsSheet2()
    Dim LastRow As Long, Erow As Long
    
    LastRow = sheet2.Cells(Rows.Count, 1).End(xlUp).Row
    Erow = sheet3.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    
    For i = 3 To LastRow
    
    sheet2.Cells(i, 2).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 2)
    
    sheet2.Cells(i, 5).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 3)
    
    sheet2.Cells(i, 7).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 4)
    
    sheet2.Cells(i, 8).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 5)
    
    sheet2.Cells(i, 13).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 6)
    
    sheet2.Cells(i, 9).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 7)
    
    sheet2.Cells(i, 11).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 8)
    
    sheet2.Cells(i, 12).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 9)
    
    sheet2.Cells(i, 15).Copy
    sheet2.Paste Destination:=Worksheets("Sheet3").Cells(Erow, 10)
    
    Next i
    
    Application.CutCopyMode = False
    Worksheets("Sheet3").Columns.AutoFit
     
    Range("A1").Select
    
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Just Looking for a little help. I know I know total Newby mistake, just learning this stuff but.
    Last edited by 6StringJazzer; 03-18-2019 at 08:05 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,841

    Re: Offset Troubles

    You never change the value of Erow. Insert this into your loop:

    Erow = Erow + 1
    next i
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Offset Troubles

    You can also reduce the copy/paste to one line each:

    CopyColumnsSheet2()
    Dim LastRow As Long, Erow As Long
    
    LastRow = sheet2.Cells(Rows.Count, 1).End(xlUp).Row
    Erow = sheet3.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    
    For i = 3 To LastRow
    sheet2.Cells(i, 2).Copy Destination:=Sheet3.Cells(Erow, 2)
    sheet2.Cells(i, 5).Copy Destination:=Sheet3.Cells(Erow, 3)
    sheet2.Cells(i, 7).Copy Destination:=Sheet3.Cells(Erow, 4)
    sheet2.Cells(i, 8).Copy Destination:=Sheet3.Cells(Erow, 5)
    sheet2.Cells(i, 13).Copy Destination:=Sheet3.Cells(Erow, 6)
    sheet2.Cells(i, 9).Copy Destination:=Sheet3.Cells(Erow, 7)
    sheet2.Cells(i, 11).Copy Destination:=Sheet3.Cells(Erow, 8)
    sheet2.Cells(i, 12).Copy Destination:=Sheet3.Cells(Erow, 9)
    sheet2.Cells(i, 15).Copy Destination:=Sheet3.Cells(Erow, 10)
    Erow = Erow + 1
    Next i
    
    Sheet3.Columns.AutoFit
     
    Range("A1").Select
    
    End Sub
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] OFFSET troubles (multiple sheets)
    By tygrrboi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2013, 11:46 AM
  2. [SOLVED] Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 03:05 AM
  3. Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 02:05 AM
  4. Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 01:05 AM
  5. [SOLVED] Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 12:05 AM
  6. [SOLVED] Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-05-2005, 11:05 PM
  7. [SOLVED] Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-05-2005, 10:05 PM
  8. [SOLVED] Troubles with the OFFSET function
    By ghostrider in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-01-2005, 01:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1