Paste value once

Godwin117

Board Regular
Joined
Dec 19, 2019
Messages
61
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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,620
Office Version
  1. 2007
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,551
Messages
5,636,966
Members
416,953
Latest member
broexc

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
Top