EBoudreau

Board Regular
Joined
Aug 21, 2015
Messages
153
I'm running into a Range of Objects Worksheet Failed Error for some reason and I cant understand why.
All I did was add the following code to the set of ranges in the Target Range in the sheet code, and all of the sudden I'm having errors when entering text into the any of the cells within the ranges.
VBA Code:
B319:C419,E319:F419,L319:M419,O319:P419,V319:W419,Y319:Z319,AF319:AG419,AI319:AJ419,B424:C524,E424:F524,L424:M524,O424:P524,V424:W524,Y424:Z524,AF424:AG524,AI424:AJ524,B529:C629,E529:F629,L529:M629,O529:P629,V529:W629,Y529:Z629,AF529:AG629,AI529:AJ629

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim xHour As String
    Dim xMinute As String
    Dim xWord As String
    Dim rngMonitored As Range, Rng As Range
    
    Set rngMonitored = Intersect(Target, Range("B4:C104,E4:F104,L4:M104,O4:P104,V4:W104,Y4:Z104,AF4:AG104,AI4:AJ104,B109:C209,E109:F1209,L109:M1209,O109:P209,V109:W209,Y109:Z209,AF109:AG209,AI109:AJ209,B214:C314,E214:F314,L214:M314,O214:P314,V214:W314,Y214:Z314,AF214:AG314,AI214:AJ314,B319:C419,E319:F419,L319:M419,O319:P419,V319:W419,Y319:Z319,AF319:AG419,AI319:AJ419,B424:C524,E424:F524,L424:M524,O424:P524,V424:W524,Y424:Z524,AF424:AG524,AI424:AJ524,B529:C629,E529:F629,L529:M629,O529:P629,V529:W629,Y529:Z629,AF529:AG629,AI529:AJ629"))
    If rngMonitored Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    
    For Each Rng In rngMonitored
        xWord = Format(Rng.Value, "0000")
        xHour = Left(xWord, 2)
        xMinute = Right(xWord, 2)
        On Error Resume Next
        Rng.Value = TimeValue(xHour & ":" & xMinute)
    Next Rng
    
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        True, AllowFormattingColumns:=Fasle, AllowFormattingRows:=True, Password:="WellingtonFrac"
    Application.EnableEvents = True
    

End Sub
 

Attachments

  • Debug Window.PNG
    Debug Window.PNG
    188.7 KB · Views: 11
  • Range of Objects Error.PNG
    Range of Objects Error.PNG
    9.4 KB · Views: 12

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.
You will need to split the range down abit & join them together like
VBA Code:
    Set r = Range("B4:C104,E4:F104,L4:M104,O4:P104,V4:W104,Y4:Z104,AF4:AG104,AI4:AJ104,B109:C209,E109:F1209,L109:M1209,O109:P209,V109:W209,Y109:Z209,AF109:AG209")
    Set r = Union(r, Range("AI109:AJ209,B214:C314,E214:F314,L214:M314,O214:P314,V214:W314,Y214:Z314,AF214:AG314,AI214:AJ314,B319:C419,E319:F419,L319:M419,O319:P419"))
    Set r = Union(r, Range("V319:W419,Y319:Z319,AF319:AG419,AI319:AJ419,B424:C524,E424:F524,L424:M524,O424:P524,V424:W524,Y424:Z524,AF424:AG524,AI424:AJ524,B529:C629,E529:F629,L529:M629,O529:P629,V529:W629,Y529:Z629,AF529:AG629,AI529:AJ629"))
    Set rngMonitored = Intersect(Target, r)
 
Upvote 0
Solution
You will need to split the range down abit & join them together like
VBA Code:
    Set r = Range("B4:C104,E4:F104,L4:M104,O4:P104,V4:W104,Y4:Z104,AF4:AG104,AI4:AJ104,B109:C209,E109:F1209,L109:M1209,O109:P209,V109:W209,Y109:Z209,AF109:AG209")
    Set r = Union(r, Range("AI109:AJ209,B214:C314,E214:F314,L214:M314,O214:P314,V214:W314,Y214:Z314,AF214:AG314,AI214:AJ314,B319:C419,E319:F419,L319:M419,O319:P419"))
    Set r = Union(r, Range("V319:W419,Y319:Z319,AF319:AG419,AI319:AJ419,B424:C524,E424:F524,L424:M524,O424:P524,V424:W524,Y424:Z524,AF424:AG524,AI424:AJ524,B529:C629,E529:F629,L529:M629,O529:P629,V529:W629,Y529:Z629,AF529:AG629,AI529:AJ629"))
    Set rngMonitored = Intersect(Target, r)
Thanks a ton? Thank worked! I didn't know that was a requirement. Was it just because the line got too long?
 
Upvote 0

Forum statistics

Threads
1,215,601
Messages
6,125,758
Members
449,259
Latest member
rehanahmadawan

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