VBA code to divide range of cells by 1000 excluding blank and formula cells

ArslanButt

New Member
Joined
Nov 10, 2018
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi every one, i am newly registered but have been a vivid follower of this forum since last couple of year. Can anyone write a short code as i need to divide range of cells by 1000 but exclude blank and formula cells ? Any help will be highly appreciated.
 
As stated...

If there are no real numbers in the range it does error.
:banghead: I seem to be dense this morning. I read your "in the selection" as meaning along with other real numbers and completely forgot about the "no cells found" error when only non-(real) numbers were the only thing in the selection. Sorry... you are correct, of course... an On Error trap is needed with my code as well.
 
Last edited:
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I get Error 13 with this line:
Code:
Ar = Ar / 1000
Need to use this instead :
Code:
Ar = Evaluate(Ar.Address & "/ 1000")
 
Upvote 0
Depending upon the data to process, this might be more efficient :
Code:
Sub DivideBy1000()
Dim rng As Range
On Error Resume Next
Set rng = Selection.SpecialCells(xlConstants, 1)
On Error GoTo 0
If Not rng Is Nothing Then
    With Cells(Rows.Count, "A").End(xlUp)(2)
        .Value = 1000
        .Copy
        rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlDivide
        Application.CutCopyMode = False
        .ClearContents
    End With
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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