visual studio vb - Convert cell (Excel) address from “C15” to Row = 15 and Column = 3











up vote
0
down vote

favorite












I have a simple application that is required to access Excel files, inject some data into selected cells, and retrieve calculated results from yet another cell.



All cells references are received in the form <letter(s)><number> (e.g. G35).



The problem is that the way to access the cells within Visual Studio (as far as I could find) is by using Row and Column values.



Is there a simple way to convert letter-number format to Row-Column format? Or, alternatively, access cells using the letter-number format.










share|improve this question




















  • 1




    If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references
    – SSS
    Oct 16 '17 at 6:40










  • Yes @SSS That's exactly what I found few minutes after posting the question. Wanted to delete the question but you were too quick :-). I'll flag it anyway.
    – FDavidov
    Oct 16 '17 at 7:02















up vote
0
down vote

favorite












I have a simple application that is required to access Excel files, inject some data into selected cells, and retrieve calculated results from yet another cell.



All cells references are received in the form <letter(s)><number> (e.g. G35).



The problem is that the way to access the cells within Visual Studio (as far as I could find) is by using Row and Column values.



Is there a simple way to convert letter-number format to Row-Column format? Or, alternatively, access cells using the letter-number format.










share|improve this question




















  • 1




    If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references
    – SSS
    Oct 16 '17 at 6:40










  • Yes @SSS That's exactly what I found few minutes after posting the question. Wanted to delete the question but you were too quick :-). I'll flag it anyway.
    – FDavidov
    Oct 16 '17 at 7:02













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a simple application that is required to access Excel files, inject some data into selected cells, and retrieve calculated results from yet another cell.



All cells references are received in the form <letter(s)><number> (e.g. G35).



The problem is that the way to access the cells within Visual Studio (as far as I could find) is by using Row and Column values.



Is there a simple way to convert letter-number format to Row-Column format? Or, alternatively, access cells using the letter-number format.










share|improve this question















I have a simple application that is required to access Excel files, inject some data into selected cells, and retrieve calculated results from yet another cell.



All cells references are received in the form <letter(s)><number> (e.g. G35).



The problem is that the way to access the cells within Visual Studio (as far as I could find) is by using Row and Column values.



Is there a simple way to convert letter-number format to Row-Column format? Or, alternatively, access cells using the letter-number format.







excel vb.net reference






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 5:17

























asked Oct 16 '17 at 6:30









FDavidov

2,31341129




2,31341129








  • 1




    If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references
    – SSS
    Oct 16 '17 at 6:40










  • Yes @SSS That's exactly what I found few minutes after posting the question. Wanted to delete the question but you were too quick :-). I'll flag it anyway.
    – FDavidov
    Oct 16 '17 at 7:02














  • 1




    If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references
    – SSS
    Oct 16 '17 at 6:40










  • Yes @SSS That's exactly what I found few minutes after posting the question. Wanted to delete the question but you were too quick :-). I'll flag it anyway.
    – FDavidov
    Oct 16 '17 at 7:02








1




1




If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references
– SSS
Oct 16 '17 at 6:40




If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references
– SSS
Oct 16 '17 at 6:40












Yes @SSS That's exactly what I found few minutes after posting the question. Wanted to delete the question but you were too quick :-). I'll flag it anyway.
– FDavidov
Oct 16 '17 at 7:02




Yes @SSS That's exactly what I found few minutes after posting the question. Wanted to delete the question but you were too quick :-). I'll flag it anyway.
– FDavidov
Oct 16 '17 at 7:02












1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references



To convert a 0-based column index to the equivalent column heading, use the following:



Private Function xlCol(ByVal col As Integer) As String
'col -= 1 'Uncomment this line if you are using 1-based column indices
Dim s As String = ""
If col < 0 Or col > 16383 Then
Throw New ArgumentException(String.Format("{0} is an invalid column", col), "col")
End If
If col >= 26 ^ 2 Then
s = Chr(64 + (col 26 26) Mod 26)
End If
If col >= 26 Then
s &= Chr(64 + (col 26) Mod 26)
End If
s &= Chr(65 + (col Mod 26))
Return s
End Function


According to this link, an Excel spreadsheet cannot have more than 16384 columns (column index 16383 or heading XFD).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46764166%2fvisual-studio-vb-convert-cell-excel-address-from-c15-to-row-15-and-colum%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references



    To convert a 0-based column index to the equivalent column heading, use the following:



    Private Function xlCol(ByVal col As Integer) As String
    'col -= 1 'Uncomment this line if you are using 1-based column indices
    Dim s As String = ""
    If col < 0 Or col > 16383 Then
    Throw New ArgumentException(String.Format("{0} is an invalid column", col), "col")
    End If
    If col >= 26 ^ 2 Then
    s = Chr(64 + (col 26 26) Mod 26)
    End If
    If col >= 26 Then
    s &= Chr(64 + (col 26) Mod 26)
    End If
    s &= Chr(65 + (col Mod 26))
    Return s
    End Function


    According to this link, an Excel spreadsheet cannot have more than 16384 columns (column index 16383 or heading XFD).






    share|improve this answer



























      up vote
      0
      down vote













      If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references



      To convert a 0-based column index to the equivalent column heading, use the following:



      Private Function xlCol(ByVal col As Integer) As String
      'col -= 1 'Uncomment this line if you are using 1-based column indices
      Dim s As String = ""
      If col < 0 Or col > 16383 Then
      Throw New ArgumentException(String.Format("{0} is an invalid column", col), "col")
      End If
      If col >= 26 ^ 2 Then
      s = Chr(64 + (col 26 26) Mod 26)
      End If
      If col >= 26 Then
      s &= Chr(64 + (col 26) Mod 26)
      End If
      s &= Chr(65 + (col Mod 26))
      Return s
      End Function


      According to this link, an Excel spreadsheet cannot have more than 16384 columns (column index 16383 or heading XFD).






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references



        To convert a 0-based column index to the equivalent column heading, use the following:



        Private Function xlCol(ByVal col As Integer) As String
        'col -= 1 'Uncomment this line if you are using 1-based column indices
        Dim s As String = ""
        If col < 0 Or col > 16383 Then
        Throw New ArgumentException(String.Format("{0} is an invalid column", col), "col")
        End If
        If col >= 26 ^ 2 Then
        s = Chr(64 + (col 26 26) Mod 26)
        End If
        If col >= 26 Then
        s &= Chr(64 + (col 26) Mod 26)
        End If
        s &= Chr(65 + (col Mod 26))
        Return s
        End Function


        According to this link, an Excel spreadsheet cannot have more than 16384 columns (column index 16383 or heading XFD).






        share|improve this answer














        If you use the Worksheet.Range object, you can specify cell(s) by Excel cell references



        To convert a 0-based column index to the equivalent column heading, use the following:



        Private Function xlCol(ByVal col As Integer) As String
        'col -= 1 'Uncomment this line if you are using 1-based column indices
        Dim s As String = ""
        If col < 0 Or col > 16383 Then
        Throw New ArgumentException(String.Format("{0} is an invalid column", col), "col")
        End If
        If col >= 26 ^ 2 Then
        s = Chr(64 + (col 26 26) Mod 26)
        End If
        If col >= 26 Then
        s &= Chr(64 + (col 26) Mod 26)
        End If
        s &= Chr(65 + (col Mod 26))
        Return s
        End Function


        According to this link, an Excel spreadsheet cannot have more than 16384 columns (column index 16383 or heading XFD).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 16 '17 at 7:23

























        answered Oct 16 '17 at 7:15









        SSS

        4,36811336




        4,36811336






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46764166%2fvisual-studio-vb-convert-cell-excel-address-from-c15-to-row-15-and-colum%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks