macro hangs up when I run it on 67 selected ranges

keithmct

Active Member
Joined
Mar 9, 2007
Messages
254
Office Version
  1. 2021
Platform
  1. Windows
I received previous help selecting multiple (67) named ranges if they all ended in the word "prices". I wanted to take 10% tax off them all via a simple macro button that multiplied all cells by 0.909. That macro starts but then seems to halt part way through. Thoughts?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Sounds like you've created a never ending loop. Can you post the Macro?
 
Upvote 0
VBA Code:
Private Sub CommandButton1_Click()
'removeGST
For Each cell In Selection
        If cell = "" Then Exit Sub
        cell.Value = cell.Value * 0.909090909

    Next cell
 
End Sub

but when I run the macro over just one or two of the manually selected ranges it works, so .....
 
Upvote 0
Is there blank cell in selection? If there is, macro will stop at that cell and exit.
 
Upvote 0
Try this.
VBA Code:
Private Sub CommandButton1_Click()
'removeGST
Dim cell as Range
For Each cell In Selection
        If Not IsEmpty(cell) Then 
        cell.Value = cell.Value * 0.909090909

    Next cell
 
End Sub
 
Upvote 0
Is there blank cell in selection? If there is, macro will stop at that cell and exit.
why, yes there is!!. OK I've replaced blank cells with na. Now it errors with run time error 13 type mismatch at "cell.Value = cell.Value * 0.909090909"
 
Upvote 0
Or this.
VBA Code:
Private Sub CommandButton1_Click()
'removeGST
Dim cell as Range
For Each cell In Selection
        If Not cell.Value = "" Then 
        cell.Value = cell.Value * 0.909090909

    Next cell
 
End Sub
 
Upvote 0
should have known I cant multiply na by 0.90909. I'll try putting 0 instead.
edit: I cant do 0 as my markup/profit will be quoted as the full price when I just want it to not give a price at all (or give an error that will make it obvious that item is unavailable)
 
Upvote 0
or
VBA Code:
For Each cell In Selection
        On Error Resume Next
        cell.Value = cell.Value * 0.909090909
        On Error Goto 0
Next cell
 
Upvote 0
Solution

Forum statistics

Threads
1,215,205
Messages
6,123,634
Members
449,109
Latest member
Sebas8956

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