Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to address a defined column

Status
Not open for further replies.

dburks1

Technical User
Apr 11, 2010
8
US
I am moving columns from one worksheet to another. In doing so I am using the scrip to copy the entire column.

ColumnsToCopy = Array("State", "City", "Address", "Phone")
Set SourceSht = ActiveSheet
Set newWbk = Workbooks.Add
Set NewSht = newWbk.Sheets(1)
NewSht.Name = "Students"

Where I get stuck is trying to address the particular column and not the range. I know that I can address a column by a range but I would rather address it by the column as the order of them might change in the future.

How would I address the "State" Column by sorting descending.
 
for each c in NewSht.columns
if c.cells(1).value="State" then colNo=c.column
next

_________________
Bob Rashkin
 


Hi,
Code:
    Set SourceSht = ActiveSheet 
    Set newWbk = Workbooks.Add
    Set NewSht = newWbk.Sheets(1)
    NewSht.Name = "Students"
   
   iCol = 1
   for each c in sourcesheet.columns
      with c
         select case c.Cells(1).value
            case "State", "City", "Address", "Phone"
               .copy
               NewSht.cells(1,iCol).pastespecial xlpasteall
               icol=icol+1
         end select
      end with
   next


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top