Paste value once

Godwin117

Board Regular
Joined
Dec 19, 2019
Messages
68
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have this VBA, however, when I run it, it repeats until I get a runtime error. I am trying to get it to where it pastes the cell's value if it reaches over a text limit. The limit would be 20. This cell(A2) has a card scanned and pastes the values of the card in the cell, instead of clicking a button every time, thought it would be quicker to have it automatically refresh if the criteria is met. There is a helper cell in G1 that verifies if the cell meets the requirements or not. Any help would be greatly appreciated.

Sub worksheet_change(ByVal target As Range)
Set target = Range("G1")
If target.Value = "YES" Then
Range("A2:C3").Select
Selection.Copy
Worksheets("Mass Assign").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Range("A2").ClearContent

End If

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
There is a helper cell in G1 that verifies if the cell meets the requirements or not.
In cell G1 do you have a formula?
Is it in cell A2 where you put the scanned data?

If the above is correct, try this:
VBA Code:
Sub worksheet_change(ByVal Target As Range)
  If Target.Address(0, 0) = "A2" Then
    If Range("G1").Value = "YES" Then
      Application.ScreenUpdating = False
      Range("A2:C3").Copy
      Worksheets("Mass Assign").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
      Application.EnableEvents = False
      Range("A2").ClearContents
      Range("A2").Select
      Application.EnableEvents = True
      Application.ScreenUpdating = True
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,617
Latest member
Narendra Babu D

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