We help IT Professionals succeed at work.
Get Started

VBA Object Error

Last Modified: 2016-02-11
Hi, '
I am hoping that  you can help me with an Object error. When I run this code:

Sub Part_G()

    Call EnterNames
    Dim rngNames As Range
    Dim cntNames As Integer
    With Range("A3")
    '----Put your code below this line----
  Dim A3 As Range
  Set rngNames = Sheet1.Range("A3")
  With Sheet1
        .Names.Add Name:="rngNames", RefersTo:=Range(rngNames.Offset(0, 0), _
    End With
    End With
With Range("A3")
  Set cntNames = Sheet1.Range("A3")
  With Sheet1
  cntNames = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
    MsgBox "Part G:  Number of names in the list = " & cntNames
    End With
End Sub

I get an object defined error on the "cntNames" variable . I am stumped. What am I missing?

Watch Question
US Data Team Lead
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE