If statement problem - #div/0!

jgold20

Board Regular
Joined
Feb 4, 2018
Messages
135
Cubic feet Filing or Scheduling & CC FeesMinimum MoveCompany CodeEnter Minimum Move Amount Minimum [FONT=&quot]Price [/FONT]per[FONT=&quot]CF [/FONT]
YESYESL500#DIV/0!
N #DIV/0!
NO #DIV/0!
#DIV/0!

<colgroup><col width="91" style="width: 68pt;"><col width="99" style="width: 74pt;"><col width="89" style="width: 67pt;"><col width="99" style="width: 74pt;"><col width="123" style="width: 92pt;"><col width="97" style="width: 73pt;"></colgroup><tbody>
</tbody>
In the above example, when cubic feet is 0, it returns a #div/0! error. The statement I am using is =IF(G3="YES",(I3/E3),0) for minimum move. If I use the drop down and change minimum move to NO, it returns a 0. I have tried everything I could think of and still receive the #div/0!. Is there any way to avoid the error. I understand why it is happening
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Right-click on the Sheet tab name at the bottom of the screen, select "View Code", and paste this code in the resulting VB Editor Window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim cell As Range

'   Check to see if cell G3 updated
    If Target.Address = Range("G3").Address And Target = "Yes" Then
        For Each cell In Range("J3:J6")
            cell.Offset(6, -5).Value = cell.Value
        Next cell
    End If
        
End Sub
When cell G3 is updated to "Yes", this code will automatically copy the values from J3:J6 to E9:E12.
 
Upvote 0
Ty. It might take me a bit to figure out how to add a second VBA on my Mac running Excel 2016. I will let you know when I have the results
 
Upvote 0
It might take me a bit to figure out how to add a second VBA on my Mac running Excel 2016.
I don't use a Mac, but did you try what I recommended?
Right-click on the Sheet tab name at the bottom of the screen, select "View Code", and paste this code in the resulting VB Editor Window:
Otherwise, you can just go into the VB Editor, open the VB Project Explorer, double-click on the sheet name you want this to apply to, and paste the VBA code in that window.
(It NEEDS to be in the proper Sheet Module to run automatically).
 
Upvote 0
Receiving the below error in the red bold line:

run time error 13
type mismatch

Sub Clearselected()
Range("e3").ClearContents
Range("e9", "e12").ClearContents
Range("H9", "H12").ClearContents
Range("i3", "i6").ClearContents
Range("K9", "K12").ClearContents
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)


Dim cell As Range


' Check to see if cell G3 updated
If Target.Address = Range("G3").Address And Target = "Yes" Then
For Each cell In Range("J3:J6")
cell.Offset(6, -5).Value = cell.Value
Next cell
End If

End Sub
 
Upvote 0
Is it in the same Module as your other code? They usually aren't located in the same modules.
What is the name of the module that the code is in>

The code I gave you is Event Procedure code that MUST go in the appropriate Worksheet module.
The other code is typically found in a Standard module.
 
Upvote 0
It is in the same module. The name is clearselected. They are both supposed to be in the same worksheet. Looking at the top left of clearselected, it is in general. It is 2:30am where I am, I will take a look tomorrow. Thank you for your help, I will let you know the result tomorrow.
 
Upvote 0
It is in the same module. The name is clearselected.
Your Clearselected procedure can go in the clearselected module, but the code I gave you cannot.
That code will only work if placed in the proper sheet module (and it must have that exact name - that is how Automated Event Procedures work - they must follow these strict guidelines).

See here for more details on Event Procedure code: http://what-when-how.com/excel-vba/automatic-procedures-and-events-in-excel-vba/

Note: It doesn't matter that your other code is not in the same module. Standard/general modules like that one can run against any sheet in the workbook.
 
Last edited:
Upvote 0
I had a little time this morning:
1) Inside of visual basic I click on insert module
2) The vba code window opens up
a) The top left dropdown window only has 1 option - GENERAL, according to docs I should be able to select WORKBOOK
b) The top right dropdown window only has 1 option - DECLARATION according I should be able to select OPEN for the event I want to create
c) When I copy the code in, the right side dropdown name changes to Worksheet_change but the left side still will not change

Please note that a module (module1) is showing up under modules
 
Upvote 0
Inside of visual basic I click on insert module
No! You cannot put Event Procedure code in new modules like that - it won't work!!!

It discusses that in the link I provided to you.
Watch this video. In the first minute, it demonstrates EXACTLY where you need to put this type of code.
It absolutely, positively MUST go in one of the existing sheet modules, NOT in a new module that you insert.
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,219
Members
449,215
Latest member
texmansru47

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