Tried to put last row into the ranges

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Not sure why these ranges will not work with last rows added to them.

VBA Code:
          Private Sub Add_Break_Lines_Click()

                
                Dim Com As ComboBox
                Dim ws As Worksheet
                Dim LastRow As Integer
   
                   
              
  
              
               
                Set ws = Application.Workbooks("Automated Cardworker.xlsm").Worksheets("Job Card Master")
                Set Com = Me.Add_Break_Lines
                LastRow = ws.Range("A" & Rows.Count).End(xlUp).row
               
               ws.Range("P13:P299").ClearContents

               
                With ws
               
               
              
                Select Case Com.Value
                    Case ("Break Lines 1 Page Job Card")
                        Color .Range("A13:Q & Lastrow")
           
                    Case ("Break Lines 2 Page Job Card")
                        Color .Range("A13:Q61")
                        Color .Range("A66:Q & Lastrow")
              
                    Case ("Break Lines 3 Page Job Card")
                         Color .Range("A13:Q61")
                        Color .Range("A66:Q122")
                        Color .Range("A127:Q & Lastrow")
                       
                    Case ("Break Lines 4 Page Job Card")
                        Color .Range("A13:Q61")
                        Color .Range("A66:Q122")
                        Color .Range("A127:Q183")
                        Color .Range("A188:Q & Lastrow")
           
                    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:Q & Lastrow")
                End Select
               
      
            End With
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi
Is it possible that your A column doesn't have any data?
The code looks good

Excel Fun
 
Upvote 0
So the code that you have to find the last row uses column A returns 1. Change it to a row that has data so that it will return the last row
VBA Code:
LastRow = ws.Range("A" & Rows.Count).End(xlUp).row
 
Upvote 0
I tried this but still no luck

VBA Code:
[B] LastRow = ws.Range("A13" & Rows.Count).End(xlUp).row[/B]
 
Upvote 0
Maybe we just need to see a screenshot of your spreadsheet to see whats happening
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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