Gingertrees
Well-known Member
- Joined
- Sep 21, 2009
- Messages
- 697
The following code works as desired, but will be SLOW when there are more columns present (the elements are merely examples - my actual worksheets have 40+ columns and can have hundreds of rows).
I feel like this could be an array formula, but I'm just learning about those. Could someone help me?
What it does: checks to assure that the beginning columns in target worksheet match the headers needed - if e.g. the second column doesn't match, the code inserts a column and gives it the header needed.
Referencing this:
http://www.mrexcel.com/forum/excel-...atch-array-report-insert-missing-columns.html
I feel like this could be an array formula, but I'm just learning about those. Could someone help me?
What it does: checks to assure that the beginning columns in target worksheet match the headers needed - if e.g. the second column doesn't match, the code inserts a column and gives it the header needed.
Code:
Sub CHECK_COLUMNS()
If UCase(Cells(1, 1).Value) <> "CONCATENATE" Then
Columns(1).Insert
Cells(1, 1).Value = "Concatenate"
End If
If UCase(Cells(1, 2).Value) <> "REPORT ITEM NO" Then
Columns(2).Insert
Cells(1, 2).Value = "Report Item No"
End If
If UCase(Cells(1, 3).Value) <> "AREA CODE" Then
Columns(3).Insert
Cells(1, 3).Value = "Area Code"
End If
If UCase(Cells(1, 4).Value) <> "PHONE START" Then
Columns(4).Insert
Cells(1, 4).Value = "Phone Start"
End If
If UCase(Cells(1, 5).Value) <> "PHONE END" Then
Columns(5).Insert
Cells(1, 5).Value = "Phone End"
End If
If UCase(Cells(1, 6).Value) <> "NAME" Then
Columns(6).Insert
Cells(1, 6).Value = "Name"
End If
End Sub
http://www.mrexcel.com/forum/excel-...atch-array-report-insert-missing-columns.html