VBA settings for computer

UFGATORS

Board Regular
Joined
Nov 28, 2008
Messages
136
Office Version
  1. 365
Help, I have the following VBA code in my spreadsheet and it works fine on my home computer. However, when I email it works on some computers and not on others. Even on my work computer sometimes it works and some times it doesn't. I have the Macro Setting set to "Disable all macros with notification". Any ideas as to why the VBA code does not always work?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim aCell As Range

If Not Intersect(Range("G3:AK125"), Target) Is Nothing Then
For Each aCell In Target

If UCase(Range("F" & aCell.Row)) <> "N" And UCase(Range("F" & aCell.Row)) <> "Y" Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit Sub
End If

If Application.WorksheetFunction.IsText(aCell.Value) Then
If UCase(aCell.Value) = "BH" Then
If UCase(Range("F" & aCell.Row)) = "N" Or _
Cells(126, aCell.Column) < 0.9 Then
Application.EnableEvents = False
aCell.Value = 0
Application.EnableEvents = True
End If
End If
End If

If Application.WorksheetFunction.IsText(aCell.Value) Then
If UCase(aCell.Value) = "AL" Then
If UCase(Range("F" & aCell.Row)) = "N" Or _
(Range("AQ" & aCell.Row)) < "0" Or _
Cells(126, aCell.Column) < 0.9 Then
Application.EnableEvents = False
aCell.Value = 0
Application.EnableEvents = True
End If
End If
End If

Next aCell
End If

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Not sure I understand your code. Maybe this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rInt      As Range
    Dim cell      As Range
    Dim sF        As String
 
    Set rInt = Intersect(Range("G3:AK125"), Target)
 
    If Not rInt Is Nothing Then
        sF = UCase(Cells(cell.Row, "F").Value)
 
        For Each cell In rInt
            If sF <> "N" And sF <> "Y" Then
                Application.EnableEvents = False
                Application.Undo
                Application.EnableEvents = True

            Else
                Select Case UCase(cell.Text)
                    Case "BH"
                        If sF = "N" Or _
                           Cells(126, cell.Column) < 0.9 Then
                            Application.EnableEvents = False
                            cell.Value = 0
                            Application.EnableEvents = True
                        End If
                    Case "AL"
                        If sF = "N" Or _
                           Cells(cell.Row, "AQ") < 0 Or _
                           Cells(126, cell.Column) < 0.9 Then
                            Application.EnableEvents = False
                            cell.Value = 0
                            Application.EnableEvents = True
                        End If
                End Select
            End If
        Next cell
    End If
End Sub
 
Upvote 0
Help, I have the following VBA code... sometimes it works and some times it doesn't.
It's often easier to track problems down when we know what it does do, rather than what it doesn't do. :)

What does your code do? Does it stop with an error? Does it run but produce unexpected results?

Have you tried stepping through it to ensure that the code is actually being executed, and that program execution is following the path you expect it to?
 
Upvote 0
The code I'm using works fine on my home computer but when I share the workbook with others the code does not always work. I was wondering if the problem might be with the computer security settings or other settings on the computer. Because the code always works on my computer, it leads me to believe it has something to do with the settings on the other persons computer.
 
Upvote 0
That didn't really help to answer Ruddles question.
when I share the workbook with others the code does not always work
What happens, to say it doesn't work ??
Does it give an error ?
Does it give incorrect results ?
Does it do nothing at all ??
 
Upvote 0
I don't know how else to explain it. There are no error codes, no part of the code works when used on some computers not all. As I said, when I open the spreeadsheet on my computer it works fine and on some other computers, this is why I have been asking is there any secruity settings or configure setting on the computer that may be causing the code not to work. It does not make sense that it works fine on one computer and not another.
 
Upvote 0
I'm assuming that when you open the workbook you're prompted to enable macros and that you're doing so.

Set a breakpoint at the start of the code and check whether it's actually being called at all. If it's never actually being called, this will allow you to focus your attention on why that's the case.

If it is being called, try stepping through the code to see what it's doing, or trying to do. Watch which statements it's executing and see if it's visiting bits of the code you wouldn't expect it to, or not visiting bits of the code you would expect it to.
 
Upvote 0
Might be a dumb question.....but are you putting the code in a Sheet module ??
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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