Wanted to insert column in excel sheet using macro.

Closed
akumarsahu Posts 2 Registration date Sunday June 8, 2014 Status Member Last seen June 8, 2014 - Jun 8, 2014 at 05:58 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jun 9, 2014 at 05:12 AM
Sub test()
Dim j As Integer, k As Integer
j = Range("B1").End(xlToRight).Column
'j is the last column
For k = j To 2 Step -1
Range(Cells(1, k), Cells(1, k)).EntireColumn.Insert
Next k
End Sub

I have put this formula to insert the column in excel sheet nex to my data. However I am unable to stop the inserting where my data has completed. Please help me.
Related:

1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Jun 9, 2014 at 05:12 AM
suppose data is like this
1 2 3 4 5 6
your macro will get


1 <blank> 2 <blank> 3 <blank> 4 <blank> 5 <blank> 6
what else do you want.

reg code

Range(Cells(1, k), Cells(1, k)).EntireColumn.Insert
it is enough

cells(1,k).entirecolumn.insert
0