What is wrong with this line of code

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to dim rng as the range of the all the lines from row 4 down

VBA Code:
Dim rng As Range: rng = range(("A4"),(O & (("A4").End(xlUp).row)))

It has an error but I can't seem to see where the error is, can someone help me please?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
What range are you trying to cover with that statement ??
 
Upvote 0
Have a look at this thread Michael. I was trying to solve little bits at a time of this problem.

 
Upvote 0
Is this what your after ?
VBA Code:
Dim rng As Range: rng = Range("A4:O" & Cells(Rows.Count, "O").End(xlUp).Row)
 
Upvote 0
Thanks Michael, with that line of code, I get the error Object variable or with block variable not set with the following part highlighted.

VBA Code:
: rng = Range("A4:O" & Cells(Rows.Count, "O").End(xlUp).Row)
 
Upvote 0
Forgot the Set
VBA Code:
Sub MM1()
Dim rng As Range: Set rng = Range("A4:O" & Cells(Rows.Count, "O").End(xlUp).Row)
End Sub
 
Upvote 0
Thanks Michael, thought I would write the extended version so I understand it better.

Excel Formula:
                                Dim LastRow As Long
                                LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
                                Dim rng As Range: Set rng = ws.Range("A4:O" & LastRow)
 
Upvote 0
Ok...whatever works best for you !
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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