Tried to put last row into the ranges

Darren Smith

Active Member
Joined
Nov 23, 2020
Messages
362
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
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

EFANYoutube

Board Regular
Joined
May 19, 2017
Messages
162
Hi
Is it possible that your A column doesn't have any data?
The code looks good

Excel Fun
 

EFANYoutube

Board Regular
Joined
May 19, 2017
Messages
162
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
 

Darren Smith

Active Member
Joined
Nov 23, 2020
Messages
362
Office Version
  1. 2019
Platform
  1. Windows

ADVERTISEMENT

I tried this but still no luck

VBA Code:
[B] LastRow = ws.Range("A13" & Rows.Count).End(xlUp).row[/B]
 

Darren Smith

Active Member
Joined
Nov 23, 2020
Messages
362
Office Version
  1. 2019
Platform
  1. Windows

ADVERTISEMENT

Could i send you the workbook via dropbox?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,316
Messages
5,623,955
Members
416,002
Latest member
t10k14

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
Top