Solved

Delete entire column using named range

Posted on 2008-06-12
1
485 Views
Last Modified: 2010-08-05
I'm missing a basic concept here on assigning ranges. What I am trying to do is delete a column that I have pre-defined as a named range.
I have attached a code snippet.
I am getting an error on line:
        ActiveSheet.Columns(rng).EntireColumn.Delete

The range "rptColSubBatch" is a valid range.
I originally defined the range as comprising the entire column E (i.e. "$E:$E")
The error generated was: Runtime Error '13'  Type Mismatch
I changed the range to comprise only the first cell in the column (i.e. $E$1)
The error generated for that range was: Runtime Error '1004'  Application-defined or Object-defined  error

Because I am working with numerous columns that may change, I need to stick with named ranges.

What am I doing wrong?

Shambalad





Public Sub DeleteColumns()

   Dim strRange As String

   Dim rng As Range

   

   strRange = "rptColSubBatch"

   Set rng = Range(strRange)

   ActiveSheet.Columns(rng).EntireColumn.Delete

End Sub

Open in new window

0
Comment
Question by:shambalad
1 Comment
 
LVL 7

Accepted Solution

by:
shambalad earned 0 total points
ID: 21773355
Figured it out.
Public Sub DeleteColumns()

   Dim strRange As String

   strRange = "rptColSubBatch"

   ActiveSheet.Columns.Range(strRange).EntireColumn.Delete

end Sub

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now