Hi, I have to following code
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 appreciatedSub 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
Last edited by TechSteff; 11-18-2011 at 08:25 AM.
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
Works perfectly thanks Nilem.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks