PDA

View Full Version : Delete Multiple cols in Excel VBA



karthikin
12-16-2011, 05:37 AM
How can i perform delete multiple cols in Excel using VBA.
My approach is like this:

Workbooks.OpenText Filename:="C:\Users\karthic.rangaraj\Desktop\4412_CARQUEF.csv"

' Parse it using comma and semicolon as delimiters
Range(Range("A1"), Range("A1").End(xlDown)).TextToColumns _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=True, Comma:=True, Space:=False, Other:=False, _
FieldInfo:= _
Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 1), Array(5, 2))

' Delete columns of ComputerSerial & UserName

Columns("B:B").Select
Selection.Delete Shift:=xlToLeft

Columns("C:C").Select
Selection.Delete Shift:=xlToLeft

"Computer Name","Computer Serial","User name","Employee Number","Software name" --> this is the first line in the csv file & then i use the above code. It does exactly to remove the quotations, comma etc..but when i want to delete the "Computer Serial","User name" at the same it's not working.
How can i delete B & C cols at the same time??? How can i create a executable macro in my Excel.

Thanks guys!!

karthikin
12-16-2011, 05:48 AM
Range("B:B,C:C").Delete - used this one & it works now.

Still i need information to create a executable macro???

Simon Lloyd
12-16-2011, 06:01 AM
I have no idea what you mean, you simply put that in your macro somewhere or as a macro you call like thisSub MyMacro()
'my code here
'mor of mycode
Call DelCols
'more of my code
'more again
End sub


Sub DelCols()
Range("D:E,G:H,J:K,M:N").EntireColumn.Delete
End Sub

karthikin
12-16-2011, 06:10 AM
Thanks. Could u please tell me, how can i look for a text in a cell if there is a match then paste in the next cell.



Mise Ã* jour de sécurité pour Windows XP (KB970430)
Mise Ã* jour pour Windows XP (KB908531)
Correctif pour Windows XP (KB961118)
Mise Ã* jour de sécurité pour Windows XP (KB956744)
Avenue Single User
IBM iSeries Access for Windows
E3 Graphics Base
Désinstallation du logiciel d''imprimante IBM
IBM Software Delivery Center Client and Agent
Correctif Windows XP - KB867282
Correctif Windows XP - KB873333

I want to look for windows xp if it's matches then paste in the next cell, like that i want to check for IBM, Dell, Adobe, VLC etc.. Thanks for your support.