I am currently tryinig to hardcopy data from one sheet1 (Output for Exact) to a different sheet2 (Hard Output Accruals). Column I in both sheets provides a description that can be either Mark-up or Accrual. My goal is to hard copy all rows from sheet1 to sheet2 where Column I indicates an Accrual. However, when I try to run my code, it does not work (select method of range class failed).
Any suggestions?
PS. the code is based on the following tutorial: https://www.youtube.com/watch?v=qGZQIl9JJk4
Kind regards,
Hajo
Here is the code:
Sub Coentunnel_Accruals()
' Coentunnel Macro
If Worksheets("Checks").Range("C2").Value > 0.01 Then
MsgBox "One or multiple checks is/are invalid"
Exit Sub
End If
a = Worksheets("Output for Exact").Cells(Rows.Count, 9).End(xlUp).Row
For i = 2 To a
If Worksheets("Output for Exact").Cells(i, 9).Value = "Accruals" Then
Worksheets("Output for Exact").Rows(i).Copy
Worksheets("Hard Output Accruals").Activate
b = Worksheets("Hard Output Accruals").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Hard Output Accruals").Cells(b + 1, 1).Select
ActivateSheet.PasteSpecial Paste:=xlPasteValues
Worksheets("Output for Exact").Activate
End If
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Output for Exact").Cells(1, 1).Select
End Sub
I tried changing the codes where I would not activate any sheets and not select any sheets. I first used the following simple code:
If Worksheets("Output for Exact").Range("I2").Value = "Accrual" Then
Worksheets("Output for Exact").Range("A2:W39").Copy
Worksheets("Hard Ouput Accruals").Range("A2").PasteSpecial Paste:=xlPasteValues
However, this only considers the value in I2, and does not go through all rows to see whether it is an accrual and only copies the data for which I2 is the accrual.
This is an oversimplified version of your code... but I think you can combine the two/edit as needed from there.
Essentially in my dumbed down version I was copying all rows with the words "Yes" in column I on Sheet3, then pasting them as values on Sheet4. In your scenario obviously change "Yes" to "Accruals" and change Sheet3 and Sheet4 to the names of your Sheets