Macro - apply calculation on selected cell, round() copy result to clipboard

mrwul62

Board Regular
Joined
Jan 3, 2016
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Up front: I am not an expert...
Hence I don't know whether the below is possible.

So far I proceed like this (example)
in A1: 25
in C1 : =A1*1,2345 (this is an example, within the macro it is fixed number though)
in D1: =round(C1;2)
result to clipboard

in B1: copy-paste clipboard as values

Again, no idea whether at all it is possible.

-select a cell
-run a macro that performs the calculation on the selected cell, rounded off and place the result in clipboard
-ctrl-v the result

Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about something like this?
VBA Code:
Dim Factor As Double

    Factor = 1.2345

    Range("B1").Value = Evaluate("ROUND(A1*" & Factor & ", 2)")
 
Upvote 0
VBA Code:
Sub jec()
factor = 1.2345
Range("B1").Value = Round([A1] * factor, 2)
End Sub
 
Upvote 0
Evaluate would be like this

VBA Code:
Sub jec()
factor = "1.2345"
Range("B1").Value = Evaluate("ROUND(A1" & "*" & factor & ", 2)")
End Sub
 
Upvote 0
Many thanks for the quick reply, really appreciated.
Please note that I took 'A1' as an example.
It could be any cell.
Meaning to say that A1 could be something like 'select cell' or so, could as well be P2893
The vba code above , does it allow free selection of cell ?
dumb question maybe...
As said, far, I mean far.... from being an expert...
 
Upvote 0
Well, like this. Including some validation

VBA Code:
Sub jec()
 factor = 1.2345
 If IsNumeric(ActiveCell) Then
   Range("B1").Value = Round(ActiveCell * factor, 2)
 Else
   MsgBox "cell is not numeric", vbOKOnly, "attention"
 End If
End Sub
 
Upvote 0
Thanks again!
Would it be possible copy the results to clipboard one way or the other?
in my first post after the calculation 'Result to clipboard'.
Then I can paste it anywhere, in my example in B1, but usually it is pasted left or right of the source cell (as converted value)

Right now I need an extra column to round off the results of the calculation.

I wish I knew how it could be done with 1 formula, but I guess it isn't possible.

SnagIt-24122021 134133.png
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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