Copy and paste vba crash

I am trying to copy a range and paste it as values ​​using vba, but it seems to go through the codes, but did nothing, because I still have formulas after I run it.

Column R and S are the only places that have formulas, and I tried F8 and it went through everything without just doing its job? Maybe I got the wrong codes to insert as values, but here they are. All columns have the same number of rows. Thus, there are no errors that simply were not copied and pasted as values.

If someone can recommend a more efficient way to copy and paste a range as values, please share as well.

Sub test()
 Dim ws2 As Worksheet
 Dim LR3 As Long
Set ws2 = Worksheets("BRST")
LR3 = ws2.Cells(ws2.Rows.Count, "R").End(xlUp).Row
ws2.Range("R3", "S" & LR3).Copy
ws2.Range("R3", "S" & LR3).PasteSpecial xlPasteValues
End Sub
+4
source share
2 answers

You should avoid using Copyit Pastein VBA, as it is much slower than just talking to the cells themselves, if you just want to replace the formulas in the cells working from R3the last row to the column S, then use this instead:

Sub test()

Dim ws2 As Worksheet
Dim LR3 As Long

Set ws2 = Worksheets("BRST")
LR3 = ws2.Cells(ws2.Rows.Count, "R").End(xlUp).Row

ws2.Range("R3", "S" & LR3).Value = ws2.Range("R3", "S" & LR3).Value

End Sub
+4
source

If you just want to convert the range to values:

With ws2.Range("R3", "S" & LR3)
    .Value = .Value
End With
+1
source

Source: https://habr.com/ru/post/1665905/


All Articles