John.McLaughlin
Board Regular
- Joined
- Jul 19, 2011
- Messages
- 169
Hello, would conditional formatting of the destination cells cause this error?
Thanks in advance!
Thanks in advance!
Code:
Sub Post()
Application.CutCopyMode = False
Dim DstRng As Range
Dim DstWks As Worksheet
Dim LastRow As Long
Dim N As Long, r As Long
Dim SrcRng As Range
Dim SrcWks As Worksheet
Sheets("SHEET2").Visible = True
Sheets("SHEET1").Visible = True
Sheets("SHEET1").Select
ActiveSheet.Unprotect
' Assign the Worksheets
Set SrcWks = Worksheets("SHEET2")
Set DstWks = Worksheets("SHEET1")
' Get all cells in the Source Range starting with row 5
Set SrcRng = SrcWks.Range("A5:E5")
LastRow = SrcWks.Cells(Rows.Count, "A").End(xlUp).Row
If LastRow < SrcRng.Row Then Exit Sub Else Set SrcRng = SrcRng.Resize(LastRow - SrcRng.Row + 1, 5)
' Find the next empty row in the Destination Range starting at row 5
Set DstRng = DstWks.Range("B5")
LastRow = DstWks.Cells(Rows.Count, "B").End(xlUp).Row
Set DstRng = IIf(LastRow < DstRng.Row, DstRng, DstRng.Offset(LastRow - DstRng.Row + 1, 0))
' This is the paste of the text
DstRng.Select
' This is the line that stops the code
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("SHEET2").Select
Range("B5").Select
End Sub