ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need a Marco to find and delete an entire column based on text sea (https://www.excelbanter.com/excel-programming/411655-need-marco-find-delete-entire-column-based-text-sea.html)

Rockpaw

Need a Marco to find and delete an entire column based on text sea
 
I have a SQL export which comes as an excel file containing a large amount of
data I don't need. I would like to write a macro to find and organize the
data based on the column headings, however, the columns are variable so I
cannot use the column reference. I.e. I need to find the column with the
title "owner" which could be column D or column F or Column HH. Any advice
would be much appricaiate. Also, if you could suggest how to move and delete
columns... many thanks.


Per Jessen

Need a Marco to find and delete an entire column based on text sea
 
Hi

This will get you started.

Sub Owner()
Dim f As Variant
Set f = Rows(1).Find(What:="owner", LookAt:=xlWhole)
If Not f Is Nothing Then
TargetColumn = f.Column
Else
Msg = MsgBox("Column not found!", vbInformation, "Warning")
End If
Columns("A").Cut Columns("D") 'Move column A to column D
Columns("D").Delete 'Delete column D
End Sub

Regards,
Per

"Rockpaw" skrev i meddelelsen
...
I have a SQL export which comes as an excel file containing a large amount
of
data I don't need. I would like to write a macro to find and organize the
data based on the column headings, however, the columns are variable so I
cannot use the column reference. I.e. I need to find the column with the
title "owner" which could be column D or column F or Column HH. Any
advice
would be much appricaiate. Also, if you could suggest how to move and
delete
columns... many thanks.




All times are GMT +1. The time now is 08:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com