PDA

View Full Version : xldown and redefine the column name macro



shingo108
2011-06-23, 06:54 PM
Good day Guys , I am new to here and seeking great help from you guys, I need a macro that , when i toggle the macro, it will go to every column xldown and redefine the column name using the top name like alpha beta and carrot, if i input another info in the column it will auto redefine it to group it to the same column name....

alpha | Beta | Carrot
asd |asd | asd
asd |asd | asd
asd |asd |
asd | |

i want to be when i input new data to the existing column, it will select until the xldown and redefine the column name by using the top name....

Hope to get the answer from you guyz soon...

Bob Phillips
2011-06-23, 07:23 PM
Dim Lastrow As Long, Lastcol As Long
Dim i As Long

With ActiveSheet

Lastcol = .Range("A1").End(xlToRight).Column
For i = 1 To Lastcol

Lastrow = .Cells(1, i).End(xlDown).Row
.Names.Add Name:=.Cells(1, i).Value2, RefersTo:="=OFFSET(" & .Cells(1, i).Address & ",0,0,COUNTA(" & .Columns(i).Address & "),1)"
Next i
End With

shingo108
2011-06-24, 02:48 AM
I am getting run time error "1004"

the situation now is my data all in sheet 2

i use =INDIRECT(CONCATENATE(B21,"_M")) to link my sheet 2 data , i needed a code that will able to toggle the macro that when i input new data to the sheet 2 ,it will automatically redefine the whole column until x1down to the name at the top column

i am still new in this , sorry for any inconvenience and thanks for reply :confused2:

Simon Lloyd
2011-06-24, 07:03 PM
Why not attach a sample workbook, this way we can actually see your data type and structure and tailor something toward that :)