jackcell
jackcell

Reputation: 11

Excel Macro, Check for headers

I am new to VBA and I would like to check if there's any way of determining whether my excel sheet has headers. The manual way of doing it is via data,

1) Click on Data, 2) Sort 3) Check whether "My Data has headers" checkbox has been checked.

Is there any way to reproduce the steps as shown above via macro? Thanks!

Upvotes: 1

Views: 507

Answers (1)

Matts
Matts

Reputation: 1351

You can use the sort method which has an option for declaring if there are headers or not in the sheet. If you don't declare it yourself using xlYes or xlNo there is an option to use xlGuess if you want Excel to attempt to determine the header. Example:

Columns("A:C").Sort key1:=Range("C2"), _
  order1:=xlAscending, header:=xlGuess

For further info: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-sort-method-excel?query=

Upvotes: 1

Related Questions