Can't get a simple multiply macro working

Hyflex

New Member
Joined
Mar 28, 2011
Messages
40
Code:
Sub Test()
Range("J:S").SpecialCells(xlCellTypeConstants, xlNumbers).Select
        With Selection
            .Cells.Value = .Cells.Value * 2.5
        End With
End Sub

I want All cells with numbers in to be multiplied by 2.5 but if its a blank or zero to ignore the cells
 
I ran a quick test on 100,000 cells worth of data in which some were blank and the macro ran in 10 seconds.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Fixed with:

Sub test()

Dim rng As Range
Dim c As Range
Dim LR As Long
LR = Range("S" & Rows.Count).End(xlUp).Row
Set rng = Range("S1:J" & LR).SpecialCells(xlCellTypeConstants, xlNumbers)
Application.ScreenUpdating = False
For Each c In rng.Cells
If c.Value <> "" Then
c.Value = c.Value * 2.5
End If
Next
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Glad you got it working, but for whatever reason that macro seems to take a considerable more time.

Over a minute versus ten seconds. Granted on a probably a larget dataset, but a test none the less
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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