Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. Sub coladd()
  2. Dim v
  3. v = Array("column1","column2,column3, column4")
  4. Dim wb As Workbook
  5. Set wb = Workbooks.Open("C:folderexcel.xls")
  6. With wb.Sheets("sheet1")
  7.  
  8. For x = 0 To UBound(v)
  9. If .Cells(1, x + 1).Value = v(x) Then GoTo nnext
  10. If .Cells(1, x + 1) <> "" Then
  11. .Cells(1, x + 1).EntireColumn.Insert
  12. .Cells(1, x + 1).Value = v(x)
  13. End If
  14. If .Cells(1, x + 1) = "" Then
  15. .Cells(1, x + 1).Value = v(x)
  16. End If
  17. nnext:
  18. Next
  19. .Range("A1").CurrentRegion.SpecialCells(xlCellTypeBlanks).Value = 0
  20. End With
  21. wb.Save
  22. wb.Close False
  23.  
  24. ActiveWorkbook.Save
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement