Solved

Delete entire column using named range

Posted on 2008-06-12
1
504 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

707 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