Hello,
I am trying to execute the following code, but I get a runtime error 1004 (pastespecial method of range class failed). I have no idea what I am doing wrong. Any help is very much appreciated because this is stressing me out.
I am trying to execute the following code, but I get a runtime error 1004 (pastespecial method of range class failed). I have no idea what I am doing wrong. Any help is very much appreciated because this is stressing me out.
Code:
Sub ReviewedStatusReport()
'Define variables
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Dim ws2row As Integer
Dim ws3row As Integer
Dim ws4row As Integer
Dim LRow As Integer
Dim LCell As String
Dim LRelocateCells As String
Application.ScreenUpdating = False
Set ws1 = ActiveSheet
ws1.Name = "CRF Review Status"
'prepare source worksheet
Range("C1") = "Visit"
Range("B1") = "Patient"
Columns("A:I").Sort key1:=Range("C2"), order1:=xlAscending, key2:=Range("B2"), order2:=xlAscending, Header:=xlYes
'Add other worksheets
Set ws2 = ActiveWorkbook.Worksheets.Add(After:=ws1)
ws2.Name = "AE Review Status"
Set ws3 = ActiveWorkbook.Worksheets.Add(After:=ws2)
ws3.Name = "ConMed Review Status"
Set ws4 = ActiveWorkbook.Worksheets.Add(After:=ws3)
ws4.Name = "ConProcedure Review Status"
ws2row = 1
ws2.Cells(ws2row, 1) = "Site"
ws2.Cells(ws2row, 2) = "Patient"
ws2.Cells(ws2row, 3) = "Visit"
ws2.Cells(ws2row, 4) = "Visit Date"
ws2.Cells(ws2row, 5) = "CRF"
ws2.Cells(ws2row, 6) = "Page Status"
ws2.Cells(ws2row, 7) = "Monitored?"
ws2.Cells(ws2row, 8) = "Reviewed?"
ws2.Cells(ws2row, 9) = "Locked?"
ws3row = 1
ws3.Cells(ws3row, 1) = "Site"
ws3.Cells(ws3row, 2) = "Patient"
ws3.Cells(ws3row, 3) = "Visit"
ws3.Cells(ws3row, 4) = "Visit Date"
ws3.Cells(ws3row, 5) = "CRF"
ws3.Cells(ws3row, 6) = "Page Status"
ws3.Cells(ws3row, 7) = "Monitored?"
ws3.Cells(ws3row, 8) = "Reviewed?"
ws3.Cells(ws3row, 9) = "Locked?"
ws4row = 1
ws4.Cells(ws4row, 1) = "Site"
ws4.Cells(ws4row, 2) = "Patient"
ws4.Cells(ws4row, 3) = "Visit"
ws4.Cells(ws4row, 4) = "Visit Date"
ws4.Cells(ws4row, 5) = "CRF"
ws4.Cells(ws4row, 6) = "Page Status"
ws4.Cells(ws4row, 7) = "Monitored?"
ws4.Cells(ws4row, 8) = "Reviewed?"
ws4.Cells(ws4row, 9) = "Locked?"
'Selecting and moving the AE data to the AE Reviewed Status sheet
ws1.Select
LRow = 2
While LRow < 10000
LCell = Range("C" & LRow).Value
LRelocateCells = "A" & LRow & ":" & "I" & LRow
Select Case LCell
Case "ADVERSE EVENTS"
Range(LRelocateCells).Cut
ws2.Select
Range(LRelocateCells).PasteSpecial
End Select
LRow = LRow + 1
Wend
End Sub
Last edited by a moderator: