Resizing a Range

  • Thread starter Thread starter NetWave128
  • Start date Start date
N

NetWave128

This line in my code keeps crashing it says:" Object Variable or Wit
block variable not set"

HERE IS THE LINE:


Dim MyRange as Range

MyRange
ThisWorkbook.Worksheets("Sheet1").Range("a1").CurrentRegion.Resize(MyRange.Rows.Count
1)


Thank you for your help
 
if you are trying to set a variable to a range object, you have to use set
before the variable name

Set MyRange = ThisWorkbook.Work...

Paul D
 
In the portion of the code "MyRange.Rows.Count", MyRange doesn't refer
to anything. The code can't cause a count of the number of rows in
MyRange because it doesn't yet know what MyRange is.

Alan Beban
 
This line in my code keeps crashing it says:" Object Variable or With
block variable not set"

HERE IS THE LINE:


Dim MyRange as Range

MyRange =
ThisWorkbook.Worksheets("Sheet1").Range("a1").CurrentRegion.Resize(MyRange.Rows.Count,
1)

try this:

With ThisWorkbook.Worksheets("Sheet1").Range("a1")
Set MyRange = .CurrentRegion.Resize(.CurrentRegion.Rows.Count, 1)
End With

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top