Link to home
Create AccountLog in
Avatar of vb7guy
vb7guyFlag for United States of America

asked on

Get Excel Column Header using Vbscript

Hi,  I have a Vbscript that read an Excel file and searches for bad Email addresses in one Column.  So Far, most of the script is working.  I ask user to enter a Column number containing Email address.  In my test the Column number is 6. I read the data by reading one cell at a time and marks all cell that have bad email address.
The problem is that at the end of the file I have sort the worksheet based on this column number.   As of right now the following script does work.  But the column range is hard coded into my script.  Some time Email address may not be in Column 6.  So I need to figure out the Column header based on the Column number they provided.

Set objRange = currentWorkSheet.UsedRange
Set objRange2 = objExcel.Range("F1")
objRange.Sort(objRange2)
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Use this....
Set objRange2 = objExcel.Cells(1, ColumnNumber)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ahammar
ahammar
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks for the points and the grade...

You should have atleast split the points though...Webtubbs pretty much had the same answer and was first...

:-)
Albert
Avatar of vb7guy

ASKER

Thanks for Help
Avatar of vb7guy

ASKER

Hi "ahammar".  I did split the Points. Each of you got "125" points
Avatar of vb7guy

ASKER

Thanks Again.
I thought maybe that's what you meant to do, but you actually split the points between 2 of my comments...I figured it was an honest mistake...

You are welcome too by the way...:-)

Albert