name every column in a table excel/vba -


i trying name each column in excel spreadsheet header. instance, if column has header "cat" want column named "cat". way can refer cat in formula, rather specifying column a:a.

i can fine single column, when try many procedure fails. here's code.

sub definename()  dim numcolumns long range("a1").select numcolumns = activesheet.cells(1, columns.count).end(xltoleft).column    columns("a:a").select cat = 0 numcolumns     selection.offset(0, i).select     activeworkbook.names.add name:=cat1, referstor1c1:="activesheet.cat1" next cat end sub 

im pretty sure problem part

 name:=cat1, referstor1c1:="activesheet.cat1" 

and not iterating think is.

i wish

 name:=[cat]1, referstor1c1:="activesheet.[cat]1" 

but not work either. have idea?

see suggestion above, here alternative code. naming whole column though doesn't seem efficient. having seen tom's suggestion, think better approach.

sub definename()  dim numcolumns long, cat long  numcolumns = activesheet.cells(1, columns.count).end(xltoleft).column  cat = 1 numcolumns     columns(cat).name = cells(1, cat) next cat  end sub 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -