VBA - Copy formula to value

MeesterMarco

New Member
Joined
May 27, 2015
Messages
5
Hi,

I am trying to make a "scoreboard". For that I have a formula in cell AD4 with the sum of a couple of cells (D4:X4) and copied that to 5 other rows. (D5:X5,D6:X6 etc.) Based on that sum the rows must be sorted in Descending order.
When I put the sum as a number in the target-column the sorting of the rows work fine. But when I use the formula there is no sorting. Seems logic to me because there is nothing to sort but a bunch of formulas.

Therefore I want VBA to copy the outcome of the formulas as a VALUE to the sorting column but I didn't manage so far. I tried to make two separate sub-routines and I tried to put them together. Removing the sorting-code doesn't do any good so the problem is probably in the copy-code itself. I'm pretty new to VBA so I probably make a basic mistake. Any help would be very much appreciated… :)

Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)


If Target.Column = 26 Then
Range("B3:Z9").Sort Key1:=Range("Z3"), _
Order1:=xlDescending, Header:=xlYes
End If


If Target.Column = 30 Then
Range("AD4:AD9").Select
Selection.Copy
Range("Z4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If


End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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