Getting Data from Excel Worksheet

grovelli
4StarLounger
Posts: 528
Joined: 26 Jan 2010, 15:14

Getting Data from Excel Worksheet

Post by grovelli »

I'm importing data from the attached Excel file which might have 24 or 25 columns, what's the code to determine how many columns the file has? I've tried using the following in an if...then...else block but it doesn't work
If xlWbk.Worksheets(1).Range("AC9").End(xlToRight).Column = 25 Then
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Getting Data from Excel Worksheet

Post by HansV »

You could look at

xlWbk.Worksheets(1).Range("E3").End(xlToRight).Column

This will be 29 if the range starting at column E has 25 columns, and 28 if it has 24 columns.
Best wishes,
Hans

grovelli
4StarLounger
Posts: 528
Joined: 26 Jan 2010, 15:14

Re: Getting Data from Excel Worksheet

Post by grovelli »

Thank you Hans :smile: