1

I am trying to sort a column using VBA in Excel. This is my code,

Range("B:B").Sort _
Key1:=Range("B2"), Order1:=xlAscending

But, It sorts the header column as well. I didn't want the Header Column to be included in the sorting , So I tried the following code,

Range("B1:B").Sort _
Key1:=Range("B2"), Order1:=xlAscending

Which didn't work either. Is there anyway to tell the VBA that my first column is a header name while sorting? Kindly share your thoughts.

1 Answer 1

5

Add the following to the code:

Header:=xlYes

So it becomes:

Range("B:B").Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.