select columns by text in first cell

  • Thread starter Thread starter zedascouves
  • Start date Start date
Z

zedascouves

I'm trying to select a whole column (and eventually only the filled
cells) by the text on its first row. The code I have by now is this:
--
For Each col In Worksheets
Select Case Columns.Name
Case "text-in-first-cell"
Columns.Select
Selection.Copy
MsgBox "The selection object type is " &
TypeName(Selection)
End Select
Next
--

It returns the error "Application-defined or object-defined error".

It's the first time I'm trying to code anything in VB, so any help
would be very appreciated.

Thank you.
Duarte
 
Dim icol as Long, col as Range
Icol = 1
For Each col In Range("A1:IV1")
Select Case lcase(col.text)
Case "text-in-first-cell"
col.EntireColumn.Copy Worksheets( _
"Destination").Columns(icol)
End Select
Next
 
Thank you! :-D

Tom Ogilvy escreveu:
Dim icol as Long, col as Range
Icol = 1
For Each col In Range("A1:IV1")
Select Case lcase(col.text)
Case "text-in-first-cell"
col.EntireColumn.Copy Worksheets( _
"Destination").Columns(icol)
End Select
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top