I have a macro that I'm using to copy a column of numbers then paste the column on a separate sheet. The source column will change every month, so the target column is being pasted to the immediate right of the previous paste.
My problem is I don't know how to change the Macro so that it will paste special values from the source column.
Thanks in advance for any assistance.
Here is my code:
Sub HistoricalData()
Dim RI As Worksheet, Yes As Worksheet, SourceCol As Integer, SourceCells As Range
On Error GoTo Err_Handler
Set SourceSht = ThisWorkbook.Sheets("RI")
Set TargetSht = ThisWorkbook.Sheets("Yes")
Set SourceCells = SourceSht.Range("K10:K17" & SourceSht.Range("K17").End(xlUp).Row)
If TargetSht.Range("A1").Value = "" Then
SourceCol = 1
ElseIf TargetSht.Range("IV1").Value <> "" Then
MsgBox "There are no more columns available in the sheet " & TargetSht.Name, vbCritical, "No More Data Can Be Copied"
Exit Sub
Else
SourceCol = TargetSht.Range("IV1").End(xlToLeft).Column + 1
End If
TargetSht.Cells(1, SourceCol).Value = Format(Date, "MM/YYYY")
SourceCells.Copy TargetSht.Cells(2, SourceCol)
MsgBox "Data copied successfully!", vbInformation, "Process Complete"
Exit Sub
Err_Handler:
MsgBox "The following error occured:" & vbLf & "Error #: " & Err.Number & vbLf & "Description: " & Err.Description, _
vbCritical, "An Error Has Occured", Err.HelpFile, Err.HelpContext
End Sub
Bookmarks