?
Solved

AA column and beyond  causing a problem when trying to get column header information

Posted on 2011-04-20
2
Medium Priority
?
355 Views
Last Modified: 2012-05-11
previous question:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26964837.html

The code below work until the column headers get into to beyond 26 range...AA...AB..AC   etc...

 Sub ListSourceHeaders(ByVal shName As String)
        Dim i As Long
        Dim t As String
        'get the header count
        'Clears out the listview so we won't see invalid columns or sheets
        Me.lvwMap.Items.Clear()
        Me.lvwSource.Items.Clear()

        oSource.workbooks(1).SHeets(shName).Activate()
        For i = 0 To oSource.workbooks(1).SHeets(shName).UsedRange.Columns.Count
            t = ChrW(65 + i)
            Me.lvwSource.Items.Add(New ListViewItem(CType(oSource.workbooks(1).SHeets(shName).Range(t & 1).Value, String)))
        Next

    End Sub


Thanks
fordraiders
0
Comment
Question by:Fordraiders
2 Comments
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 2000 total points
ID: 35437574
Hi,
Please try it as following

Thanks
Sub ListSourceHeaders(ByVal shName As String)
        Dim i As Long
        Dim t As String
        'get the header count
        'Clears out the listview so we won't see invalid columns or sheets
        Me.lvwMap.Items.Clear()
        Me.lvwSource.Items.Clear()

        oSource.workbooks(1).SHeets(shName).Activate()
        For i = 0 To oSource.workbooks(1).SHeets(shName).UsedRange.Columns.Count
            t = GetColumnName(i)
            Me.lvwSource.Items.Add(New ListViewItem(CType(oSource.workbooks(1).SHeets(shName).Range(t & 1).Value, String)))
        Next

    End Sub


Public Function GetColumnName(ByVal i As Integer)
        Dim colName As String

        If i < 26 Then
            colName = ChrW(65 + i)
        Else
            colName = ChrW(64 + CInt(i / 26)) + ChrW(65 + (i Mod 26))
        End If

        Return colName
    End Function

Open in new window

0
 
LVL 3

Author Closing Comment

by:Fordraiders
ID: 35440610
Perfect !   A beautiful thing.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question