Help with sheet code

ASBeard

New Member
Joined
May 7, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Good morning. I have an excel file and I have written code to display a default value in approximately 400 cells. The code works correctly, however whenever I several of these cells simultaneously it causes a critical error and the excel file closes. I have placed an image of just some of the code as the mini-sheet I don't think will copy inside visual basic (if this is incorrect, please let me know). If you need to see all of the code, please don't hesitate to let me know. And just so you know, the code is entered in the 'sheet' for which the default values are to be placed and not in a module. I am hoping that there is something I can do to simplify my code to prevent the critical error. Thank you in advance for any help you can provide!
 

Attachments

  • 2024-05-07_10-48-40.png
    2024-05-07_10-48-40.png
    70 KB · Views: 8

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Remember, this is a sample. You'll need to finish the rest. I forgot to set the minor rng to the intersect

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range
  Dim cell As Range
 
  Application.EnableEvents = False
 
  Set rng = Intersect(Range("B27:B32"), Target)
  If Not rng Is Nothing Then
    For Each cell In rng
      If cell.Value = "" Then cell.Value = "(Enter Custom Label)"
    Next cell
  End If
 
  Set rng = Intersect(Range("F10"), Target)
  If Not rng Is Nothing Then
    For Each cell In rng
      If cell.Value = "" Then cell.Value = "MRN"
    Next cell
  End If
 
  Set rng = Intersect(Range("F11"), Target)
  If Not rng Is Nothing Then
    For Each cell In rng
      If cell.Value = "" Then cell.Value = "Visit Number"
    Next cell
  End If
 
  Application.EnableEvents = True
 
' . . . . . .

End Sub
 
Upvote 1
Solution
Thank you so much... so far so good but obviously I have a lot of code to add so it might be tomorrow before I can get back and let you know if it worked for all the code but its looking good so far. I cannot thank you enough!!
 
Upvote 0
Jeff I think you got it. I was able to clear the same number of cells that previously caused the fatal error. Thank you again sir!! Take care.
 
Upvote 0

Forum statistics

Threads
1,216,111
Messages
6,128,899
Members
449,477
Latest member
panjongshing

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