Can`t seem to get my code to recognize my SpreadSheet

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Problem is the worksheet for some reason will not work. It says ws = Nothing?? I have set it up same as before baffled.
I tried to set a workbook variable Then using Thisworkbook.Sheets still no luck.
Don`t Know of any other way it could or should work

VBA Code:
Private Sub Add_Break_Lines_Click()

                              
                Dim Com As ComboBox
                Dim ws As Worksheet
                Dim wb As Workbook
                
                
                Set wb = Workbooks("Automated Cardworker")
                Set ws = wb.Worksheets("Job Card Master")
                Set Com = Me.Add_Break_Lines
                

            
               With ws
               
                Select Case Com.Value
                    Case ("Break Lines 1 Page Job Card")
                        Color .Range("A13:Q61")
            
                    Case ("Break Lines 2 Page Job Card")
                        Color .Range("A13:Q61")
                        Color .Range("A66:Q120")
               
                    Case ("Break Lines 3 Page Job Card")
                         Color .Range("A13:Q61")
                        Color .Range("A66:Q122")
                        Color .Range("A127:Q178")
                        
                    Case ("Break Lines 4 Page Job Card")
                        Color .Range("A13:Q61")
                        Color .Range("A66:Q122")
                        Color .Range("A127:Q183")
                        Color .Range("A188:Q244")
            
                    Case ("Break Lines 5 Page Job Card")
                        Color .Range("A13:Q61")
                        Color .Range("A66:Q122")
                        Color .Range("A127:Q183")
                        Color .Range("A188:Q244")
                        Color .Range("A249:Q299")
                End Select
                
            End With

            End Sub
 
No, that code just calls the color routine based on the combo box choice, there will be more code somewhere.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Sorry I understand here is the function that fills the color

VBA Code:
Function Color(rng As Range)

Dim row As Range
Dim EmptyRowNum As Integer


For i = 1 To rng.Rows.Count

    Set row = rng.Rows(i)
    If WorksheetFunction.CountA(row) = 0 Then
        EmptyRowNum = EmptyRowNum + 1
    End If
    If EmptyRowNum = 2 Then
        EmptyRowNum = 0
        row.Interior.ColorIndex = 4
    End If

Next i

End Function
 
Upvote 0
Are there blank rows in the ranges you are referring to?
 
Upvote 0
There is nothing there that would cause the code to stop abruptly. Put a break point at the start of your original code, then select "Break Lines 1 Page Job Card" from the dropdown and then step through the code to see what is happening.
 
Upvote 0
I`ve stepped through the code after putting a breakpoint.
It seems to run but no color filled into the sheet rows??
 
Upvote 0
Did it actually run this line:

Code:
row.Interior.ColorIndex = 4
 
Upvote 0
If it's not running that line, then that's why you aren't seeing any colours. Does it run the line before it?
 
Upvote 0

Forum statistics

Threads
1,215,743
Messages
6,126,603
Members
449,321
Latest member
syzer

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