0

I want to insert a new column AFTER the last one that is populated. How can i find out which was the last column populated?.

e.g. i have the below headers :

Name , Date , Address 

I want to insert 'test1','test2','test3' after address. How is this possible?

Rory Lester
  • 2,858
  • 11
  • 49
  • 66
  • possible duplicate of [How can I find last row that contains data in the Excel sheet with a macro?](http://stackoverflow.com/questions/71180/how-can-i-find-last-row-that-contains-data-in-the-excel-sheet-with-a-macro) – Bulat Aug 09 '15 at 14:48
  • @Bulat, I believe Rory is looking to find the last column, not last row. – DiegoAndresJAY Aug 09 '15 at 15:28
  • Yes, I picked the wrong question, questions on last column also exist – Bulat Aug 09 '15 at 15:39

2 Answers2

0

This assumes your headers are on the first row.

Dim x as Integer
x = ActiveSheet.UsedRange.Columns.Count
ActiveSheet.Cells(1, x+1) = "Test1"
ActiveSheet.Cells(1, x+2) = "Test2"
ActiveSheet.Cells(1, x+3) = "Test3"

I recommend adding code to test and make sure your last column header isn't "Test3" already (indicating that you are adding three extra columns that you don't need).

DiegoAndresJAY
  • 706
  • 4
  • 11
0
Dim cNext as Range

Set cNext = Activesheet.Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)

cNext.resize(1, 3).value = Array("Name","Date","Address")
Tim Williams
  • 154,628
  • 8
  • 97
  • 125