Hi,
I have given to write a query. You might find my post in other forums. None of them solved my question. I hope chandoo forum would help me to get out of this.
I am comparing my array list with column headers from another excel workbook saved in folder c:\folder\excel.xls. if the workbook header doesn't contain any of the values specified in the array then it should write zero;s in my workbook.
My array list has column1,2,3,4 and my excel sheet has headers column1 and column4 only. So the code below should write column2 and column3 with zero;s in it till end.
But the below code writes column1 | column2 | column3 |column4 |column1 | column4 |
please help. It didn't work as i expected.
I have given to write a query. You might find my post in other forums. None of them solved my question. I hope chandoo forum would help me to get out of this.
I am comparing my array list with column headers from another excel workbook saved in folder c:\folder\excel.xls. if the workbook header doesn't contain any of the values specified in the array then it should write zero;s in my workbook.
My array list has column1,2,3,4 and my excel sheet has headers column1 and column4 only. So the code below should write column2 and column3 with zero;s in it till end.
But the below code writes column1 | column2 | column3 |column4 |column1 | column4 |
please help. It didn't work as i expected.
Code:
Dim v,wb As Workbook
v = Array("column1","column2","column3", "column4")
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\folder\excel.xls")
With wb.Sheets("sheetABC")
For x = 0 To UBound(v)
If .Cells(1, x + 1).Value = v(x) Then GoTo nnext
If .Cells(1, x + 1) <> "" Then
.Cells(1, x + 1).EntireColumn.Insert
.Cells(1, x + 1).Value = v(x)
End If
If .Cells(1, x + 1) = "" Then
.Cells(1, x + 1).Value = v(x)
End If
nnext:
Next
.Range("A1").CurrentRegion.SpecialCells(xlCellTypeBlanks).Value = 0
End With
wb.Save
Last edited: