VBA - Select column if value in row 1 equals

martin_j_king

New Member
Joined
Jan 28, 2011
Messages
20
Hi All,

Have a csv file which is a data dump from a db. Unfortunately, can't query the db direct because no sybase drivers.

certain columns are copied from the csv to the workbook which has summary reports.

Currently, my macro selects specific columns, or at the moment all the columns, because the column positions are changing constantly.

Is there a way which I can basically:
Search row 1, starting from A untill the last cell with data (no point searching blank) and if i find the word "total_p&l", select that column. I don't need it to store this info, just select the column.

I've been playing around with loops, if cell equals then select active column, if not move right on but i'm still not quite at the level to write full code without some help from the recorder.

thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Search row 1, starting from A untill the last cell with data (no point searching blank) and if i find the word "total_p&l", select that column. I don't need it to store this info, just select the column.

<font face=Courier New>    Range("1:1").Find(What:="total_p&l", _<br>                      LookIn:=xlValues, _<br>                      LookAt:=xlWhole, _<br>                      MatchCase:=False).EntireColumn.Select</FONT>

The .Find method
 
Last edited:
Upvote 0
Thanks for that, never knew there was a find method. The article was very useful, given me ideas for other processes. Back ground as to how it works was much appreciated
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top