|
-
Aug 29th, 2004, 05:17 AM
#1
Thread Starter
New Member
Union problem in Excel?
I wish to delete several columns on the same worksheet at one go. So Union was used to group those columns together. But Run-time error 1004 : Method ¡®Union¡¯ of object¡¯_Application¡¯ failed was returned.
Any way in getting around it please?
VB Code:
Option Explicit
Dim oExcel As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Sub DeleteData ()
Dim rngA As Range
oWB.Activate
oWB.Sheets(2).Select
'Autofit Col
oWB.Sheets(2).Columns ("A:L").EntireColumn.AutoFit
Set rngA = oExcel.Union(Columns("F"), Columns("H"))
rngA.EntireColumn.Delete
Last edited by pb1; Aug 31st, 2004 at 05:51 PM.
Give me a hand not a finger.
-
Aug 31st, 2004, 09:26 AM
#2
If the columns aren't changing then use
VB Code:
oWB.Sheets(2).Columns("A").entirecolumn.delete
Where A is the column.
Never heard of the union before.
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 31st, 2004, 04:50 PM
#3
Thread Starter
New Member
Union - range object
Union is a method of the Application Object. It returns the union of two or more ranges.
The syntax is:
VB Code:
Application.Union(Arg1, Arg2, ...)
where Arg1, Arg2, . . . are the Range objects whose ranges we wish to join together. At least two Range objects must be specified. I succeeded using union in deleting multiple rows but not columns.
Any advice would be much appreciated.
Last edited by pb1; Aug 31st, 2004 at 04:57 PM.
Give me a hand not a finger.
-
Sep 9th, 2004, 08:42 AM
#4
Lively Member
maybe stupid but why don't you just delete each column one by one
VB Code:
columns("A:B").delete
columns(yourcolumn).delete
etc
-
Sep 9th, 2004, 04:19 PM
#5
Thread Starter
New Member
Union problem solved !
Union problem solved:-
VB Code:
Dim rngA As Range
Set rngA = oExcel.Union(Range("F1:F2"), Range("H1:H2"), _
Range("J1:J2"), Range("K1:K2"))
rngA.EntireColumn.Delete
Give me a hand not a finger.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|