Copy and Paste Value

erichmiller

New Member
Joined
Jul 28, 2014
Messages
2
Hello Everyone,

I have values of what I have in stock in cells C7:C22.

I have a formula in cells H7:H22 that calculate start weight minus end weight when are entered into cells D7:D22 and E7:E22.

If the value changes in Column H which indicates we used some of the stock on hand I want the new value to be pasted into column c and the numbers entered on columns d and e to be deleted.

I have tried several things but cannot get it to run properly. Here is one of the thing sI have tried below

If E7>0 then
range("H7").Select
range("H7").Copy
range("C7").Paste
Range("E7").ClearContents
Range("D7").ClearContents
Else
End If
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I think this is what you're after. Paste it into the module of the sheet in question...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("H7:H22")) Is Nothing Then Exit Sub


Application.EnableEvents = False




With Target
    .Offset(, -5) = .Value2
    .Offset(, -4).Resize(1, 2).ClearContents
End With




Application.EnableEvents = True


End Sub
 
Upvote 0
I tried the code and it does not seem to work.

I have read through some of the online information and I have found that since the cells in column H are formula I will need to use worksheet calculate not worksheet change. this is what I tried and it did not work

Private Sub Worksheet_Calculate()
If E7 > 0 Then
Range("H7").Select
Range("H7").Copy
Range("C7").Paste
Range("E7").ClearContents
Range("D7").ClearContents
Else
End If
End Sub



I think this is what you're after. Paste it into the module of the sheet in question...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("H7:H22")) Is Nothing Then Exit Sub


Application.EnableEvents = False




With Target
    .Offset(, -5) = .Value2
    .Offset(, -4).Resize(1, 2).ClearContents
End With




Application.EnableEvents = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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