Copy paste special error

victorel21

New Member
Joined
Jul 8, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I am getting a copy paste error as it seems nothing is being pasted, could anyone help with this.

This worked fine yesterday, but today it isnt.

A

Sub todatabase2()

Dim ID, GR, Departamento, Semana, Comentarios, Month As Range

With Sheets("Form")
ID = Range("F1")
GR = Range("A3")
Departamento = Range("C3")
Semana = Range("D3")
Comentarios = Range("B25")
End With

Set Month = Sheets("Datalist").Cells(Range("E:E").Find(Semana, Lookat:=xlWhole).Row, 6)

With Sheets("Employee_List")
Set RngCol = .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
LastRow = RngCol.Rows.Count
.Range("A2:G" & LastRow + 1).Copy
End With

With Sheets("Historico")
last_line = .Range("F" & Rows.Count).End(xlUp).Row + 1
.Range("F" & last_line).PasteSpecial Paste:=xlPasteValues
Do While Cells(last_line, 6) <> ""
If .Range("F" & last_line) <> "" Then
.Range("A" & last_line) = ID
.Range("B" & last_line) = GR
.Range("C" & last_line) = Departamento
.Range("D" & last_line) = Semana
.Range("M" & last_line) = Comentarios
.Range("E" & last_line) = Month
End If
last_line = last_line + 1
Loop
End With

ThisWorkbook.Worksheets("Historico").Cells.EntireColumn.AutoFit

End Sub

Cell Formulas
RangeFormula
B2:B7B2=IF(A2="","",XLOOKUP(A2,Employees_Data!C:C,Employees_Data!A:A)& " " &XLOOKUP(A2,Employees_Data!C:C,Employees_Data!B:B))
C2:C7C2=IF(A2="","",VLOOKUP(A2,Employees_Data!C:E,3,0))
D2:D7D2=IF(A2="","",VLOOKUP(A2,Employees_Data!C:H,6,0))
E2:E7E2=IF(A2="","",IF(H2="YES",Calc!$G$2,0)+IF(I2="YES",Calc!$G$3,0)+IF(J2="YES",Calc!$G$4,0)+IF(K2="YES",Calc!$G$5,0)+IF(L2="YES",Calc!$G$6,0)+IF(M2="YES",Calc!$G$7,0)+IF(N2="YES",Calc!$G$8,0))
F2:F7F2=IF(Employee_List!$D2="","",IF(H2="YES",INDEX(Calc!$A$1:$K$8,2,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(I2="YES",INDEX(Calc!$A$1:$K$8,3,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(J2="YES",INDEX(Calc!$A$1:$K$8,4,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(K2="YES",INDEX(Calc!$A$1:$K$8,5,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(L2="YES",INDEX(Calc!$A$1:$K$8,6,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(M2="YES",INDEX(Calc!$A$1:$K$8,7,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(N2="YES",INDEX(Calc!$A$1:$K$8,8,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0))))
G2:G7G2=IF(Employee_List!$D2="","",IF(AND(H2="YES",INDEX(Calc!$A$1:$M$8,2,8)="YES"),Datalist!$C$5,0)+IF(AND(I2="YES",INDEX(Calc!$A$1:$M$8,3,8)="YES"),Datalist!$C$5,0)+IF(AND(J2="YES",INDEX(Calc!$A$1:$M$8,4,8)="YES"),Datalist!$C$5,0)+IF(AND(K2="YES",INDEX(Calc!$A$1:$M$8,5,8)="YES"),Datalist!$C$5,0)+IF(AND(L2="YES",INDEX(Calc!$A$1:$M$8,6,8)="YES"),Datalist!$C$5,0)+IF(AND(M2="YES",INDEX(Calc!$A$1:$M$8,7,8)="YES"),Datalist!$C$5,0)+IF(AND(N2="YES",INDEX(Calc!$A$1:$M$8,8,8)="YES"),Datalist!$C$5,0))
Named Ranges
NameRefers ToCells
Employees_Data!_FilterDatabase=Employees_Data!$A$1:$J$378B2:B7
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:ACell ValueduplicatestextNO
Cells with Data Validation
CellAllowCriteria
A2:A7List=OFFSET(Employees_Data!C2,0,0,COUNTA(Employees_Data!C:C)-1)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I would really have to do tests with the data in your sheets to see what is happening. You could put a sample with minisheets from your other sheets.

I anticipate that some dots are missing in your references:

Rich (BB code):
Sub todatabase2()
  Dim ID, GR, Departamento, Semana, Comentarios, Month As Range
  
  With Sheets("Form")
    ID = .Range("F1")
    GR = .Range("A3")
    Departamento = .Range("C3")
    Semana = .Range("D3")
    Comentarios = .Range("B25")
  End With
  
  Set Month = Sheets("Datalist").Cells(Sheets("Datalist").Range("E:E").Find(Semana, Lookat:=xlWhole).Row, 6)
  
  With Sheets("Employee_List")
    Set RngCol = .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
    LastRow = RngCol.Rows.Count
    .Range("A2:G" & LastRow + 1).Copy
  End With
  
  With Sheets("Historico")
    last_line = .Range("F" & Rows.Count).End(xlUp).Row + 1
    .Range("F" & last_line).PasteSpecial Paste:=xlPasteValues
    Do While .Cells(last_line, 6) <> ""
      If .Range("F" & last_line) <> "" Then
        .Range("A" & last_line) = ID
        .Range("B" & last_line) = GR
        .Range("C" & last_line) = Departamento
        .Range("D" & last_line) = Semana
        .Range("M" & last_line) = Comentarios
        .Range("E" & last_line) = Month
      End If
      last_line = last_line + 1
    Loop
  End With
  ThisWorkbook.Worksheets("Historico").Cells.EntireColumn.AutoFit
End Sub
 
Upvote 0
This is the main form

Overtime Request Form.V6 historic by employee ID.xlsm
CDE
6Hora LlegadaHora Partida Comida
716:30:0021:00:00YES
816:30:0021:00:00YES
916:30:0021:00:00YES
1016:30:0021:00:00YES
1116:30:0021:00:00YES
12
13
Form
Cells with Data Validation
CellAllowCriteria
E7:E13List=List!$D$2:$D$3


Here I do some calcs

Overtime Request Form.V6 historic by employee ID.xlsm
ABCDEFGHIJK
1DIAHora LlegadaHora Partida Horas Extras Horas extras dobles Horas nocturnas Total Horas Comida Cost Dir Cost Indir Cost Sup
2LU:16:30:0021:00:004.50--4.50YES6.638.6514.42
3MA:16:30:0021:00:004.50--4.50YES6.638.6514.42
4MIE:16:30:0021:00:004.50--4.50YES6.638.6514.42
5JUE:16:30:0021:00:004.50--4.50YES6.638.6514.42
6VIE:16:30:0021:00:004.50--4.50YES6.638.6514.42
7SA:   --- ---
8DO:   --- ---
Calc


This is the end result

Cell Formulas
RangeFormula
B2:B7B2=IF(A2="","",XLOOKUP(A2,Employees_Data!C:C,Employees_Data!A:A)& " " &XLOOKUP(A2,Employees_Data!C:C,Employees_Data!B:B))
C2:C7C2=IF(A2="","",VLOOKUP(A2,Employees_Data!C:E,3,0))
D2:D7D2=IF(A2="","",VLOOKUP(A2,Employees_Data!C:H,6,0))
E2:E7E2=IF(A2="","",IF(H2="YES",Calc!$G$2,0)+IF(I2="YES",Calc!$G$3,0)+IF(J2="YES",Calc!$G$4,0)+IF(K2="YES",Calc!$G$5,0)+IF(L2="YES",Calc!$G$6,0)+IF(M2="YES",Calc!$G$7,0)+IF(N2="YES",Calc!$G$8,0))
F2:F7F2=IF(Employee_List!$D2="","",IF(H2="YES",INDEX(Calc!$A$1:$K$8,2,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(I2="YES",INDEX(Calc!$A$1:$K$8,3,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(J2="YES",INDEX(Calc!$A$1:$K$8,4,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(K2="YES",INDEX(Calc!$A$1:$K$8,5,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(L2="YES",INDEX(Calc!$A$1:$K$8,6,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(M2="YES",INDEX(Calc!$A$1:$K$8,7,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0)))+IF(N2="YES",INDEX(Calc!$A$1:$K$8,8,MATCH("Cost"&" "&Employee_List!D2,Calc!$1:$1,0))))
G2:G7G2=IF(Employee_List!$D2="","",IF(AND(H2="YES",INDEX(Calc!$A$1:$M$8,2,8)="YES"),Datalist!$C$5,0)+IF(AND(I2="YES",INDEX(Calc!$A$1:$M$8,3,8)="YES"),Datalist!$C$5,0)+IF(AND(J2="YES",INDEX(Calc!$A$1:$M$8,4,8)="YES"),Datalist!$C$5,0)+IF(AND(K2="YES",INDEX(Calc!$A$1:$M$8,5,8)="YES"),Datalist!$C$5,0)+IF(AND(L2="YES",INDEX(Calc!$A$1:$M$8,6,8)="YES"),Datalist!$C$5,0)+IF(AND(M2="YES",INDEX(Calc!$A$1:$M$8,7,8)="YES"),Datalist!$C$5,0)+IF(AND(N2="YES",INDEX(Calc!$A$1:$M$8,8,8)="YES"),Datalist!$C$5,0))
Named Ranges
NameRefers ToCells
Employees_Data!_FilterDatabase=Employees_Data!$A$1:$J$378B2:B7
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:ACell ValueduplicatestextNO
Cells with Data Validation
CellAllowCriteria
A2:A7List=OFFSET(Employees_Data!C2,0,0,COUNTA(Employees_Data!C:C)-1)


Other sheets are just databases where the vlookups come from.


 
Upvote 0
Looks like the error was due to the sheet being protected, I tried adding a line to unprotect but it didnt help, the protection was automatic from a code in the worksheet but for some reason unprotecting didnt help. I will try different things and determine the exact reason as I need it protected.
 
Upvote 0
Solution
Hi I found the solution to be, to unprotect and protect in the same module, I no longer have the errors.
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top