Check if Columns match array, report or insert missing columns

Gingertrees

Well-known Member
Joined
Sep 21, 2009
Messages
697
How would I check to see if columns on my sheet match a set array of column names?

Array :
Code:
("Concatenate", "Report Item No", "Area Code", "Phone Start", "Phone End", "Name")

So my sheet ideally looks like this:
ConcatenateReport Item NoArea CodePhone StartPhone EndNameID23ID33ID42
5615551212BD15615551212BDoexey
6041238888AT26041238888ATannrer

<tbody>
</tbody>

I'd like info on which columns are missing. Any chance I could add code to insert missing columns at the right places??

Thanks.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello,

have hard-coded the requirements. Which will also insert the columns and its heading

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

Does this work as required?
 
Upvote 0
That does work - I am a little concerned that it will go slow when I increase the number of columns, though.
Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top