Any value greater than zero, copy , paste values only

Bdbd55

New Member
Joined
Dec 12, 2019
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am new to VBA. I thought this macro made sense but there are errors. How do I right an IF in VBA that takes any value in the sheet above 0 and only copies and pastes it's values. Please help!


Sub Sample()

Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("US Averages")

If score > 0 Then

With ws.UsedRange
.Copy
.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

End With
End If
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Welcome to the Board!

Copies and pastes the value to where?
Over top of itself, or paste it somewhere else (if somewhere else, where)?
 
Upvote 0
If you just want to paste the value over top of itself, then you can just do this:
Code:
Sub Sample()

Dim ws As Worksheet
Dim cell As Range

Set ws = ThisWorkbook.Sheets("US Averages")

For Each cell In ws.UsedRange
    If cell.Value > 0 Then cell.Value = cell.Value
Next cell

End Sub
]
 
Upvote 0
Hello,

Thank you for the fast response. And glad to be here :)

Sorry for not being clear. I would like any value greater than zero to copy and paste itself (over itself) as a value without the formula.

Once my other files feed into this and reports the averages for a day in the week it will just give me the numeric values above zero and I do not want the formula to follow.

I hope this makes sense
 
Upvote 0
The code I pasted above should do what you want then.
 
Upvote 0
You are right, thank you so much!
Is there a way to make this run automatically or when the file is opened. Sorry if these are novice questions.
 
Upvote 0
Preferably refreshed every weekday for 2020 at 6pm eastern time automatically. Is that possible?,
 
Upvote 0
Preferably refreshed every weekday for 2020 at 6pm eastern time automatically. Is that possible?,
Only if Excel and the file was always guaranteed to be open at this time (or you could schedule a job on a server to fire it off and run at this day/time).

Otherwise, you could make Excel run it every time the file was opened (it wouldn't hurt to run it more often than needed). If you don't want it to run more than once a week, you can have Excel log when it last ran (in some unused cell), and then have the job first check to see when it last ran before deciding whether or not to run again when the file opens.

Please let us know which option you would like to pursue.
 
Upvote 0
I would say it would be best for it to run every weekday during 2020 at 6pm est. If it is not too much the job on the server would make the most sense. Thanks!!
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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