+ Reply to Thread
Results 1 to 3 of 3

Thread: Move up one row than paste

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    Curacao
    MS-Off Ver
    Excel 2010
    Posts
    5

    Move up one row than paste

    Hi, I have to following code
    Sub YearTransfer()
    
    Dim CopyRange1 As Range
    Dim CopyRange2 As Range
    Dim GCell As Range
    Dim ctr, ctr2 As Long
    Dim LastRowA As Long
    Dim LastRowB As Long
    Dim newSheet, oldSheet As Integer
    
    oldSheet = CInt(ActiveSheet.Name)
    newSheet = oldSheet + 1
    
    Set sourceSheet = Sheets(CStr(oldSheet))
    Set destinationsheet = Sheets(CStr(newSheet))
    
    'LastRowA = sourceSheet.Cells(Cells.Rows.Count, "U").End(xlUp).Row
    'LastRowB = destinationSheet.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
    
    ctr = 3
    
    
    Do While Cells(ctr, 2) <> ""
    
    If (Cells(ctr, "U").Value <> 0) Then
      
            Cells(ctr, "B").Copy
            destinationsheet.Select
            Cells(ctr, "B").Select
            ActiveSheet.Paste
            sourceSheet.Select
            Cells(ctr, "C").Copy
            destinationsheet.Select
            Cells(ctr, "C").Select
            ActiveSheet.Paste
            sourceSheet.Select
            Cells(ctr, "E").Copy
            destinationsheet.Select
            Cells(ctr, "E").Select
            ActiveSheet.Paste
            sourceSheet.Select
            Cells(ctr, "F").Copy
            destinationsheet.Select
            Cells(ctr, "F").Select
            ActiveSheet.Paste
            sourceSheet.Select
    
    ctr = ctr + 1
    
    Else
    
    ctr = ctr + 1
    
    End If
    
    Loop
    What I want to do is that if U = 0 the destination row has to move up one row thus avoiding having empty rows in the destination sheet...any suggestions would be really appreciated
    Last edited by TechSteff; 11-18-2011 at 08:25 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    Excel 2010
    Posts
    522

    Re: Move up one row than paste

    Maybe this:
    Sub YearTransfer()
    
    Dim CopyRange1 As Range '?
    Dim CopyRange2 As Range '?
    Dim GCell As Range '?
    Dim ctr As Long, ctr2 As Long
    Dim LastRowA As Long
    Dim LastRowB As Long
    Dim newSheet As Integer, oldSheet As Integer
    
    oldSheet = CInt(ActiveSheet.Name)
    newSheet = oldSheet + 1
    
    Set sourceSheet = Sheets(CStr(oldSheet))
    Set destinationsheet = Sheets(CStr(newSheet))
    
    ctr = 3: ctr2 = 2
    
    With sourceSheet
        Do While Cells(ctr, 2) <> ""
            If (Cells(ctr, "U").Value <> 0) Then
                ctr2 = ctr2 + 1
                .Cells(ctr, "B").Resize(, 2).Copy destinationsheet.Cells(ctr2, "B")
                .Cells(ctr, "E").Resize(, 2).Copy destinationsheet.Cells(ctr2, "E")
            End If
            ctr = ctr + 1
        Loop
    End With
    
    End Sub

  3. #3
    Registered User
    Join Date
    11-15-2011
    Location
    Curacao
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Move up one row than paste

    Works perfectly thanks Nilem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0