Link to home
Start Free TrialLog in
Avatar of shambalad
shambaladFlag for United States of America

asked on

Delete entire column using named range

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

ASKER CERTIFIED SOLUTION
Avatar of shambalad
shambalad
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial