Range().Cells().Row












2















I was troubled by the following code



Dim xTRrow as Integer
Dim xTitle as String
Dim xSht as Worksheet
xTRrow = xSht.Range(xTitle).Cells(1).Row


I wonder what the last line does. Especially, the .Row. In case as such, how do can I run the VBA code line by line to find out what a specific line of code does? I guess something is off with the code. I've tried to display xTRrow which should be an integer. But nothing jumps on the screen. I wonder what the last option .Row does.










share|improve this question

























  • .Row returns the row number of the specified cell

    – Brotato
    Nov 23 '18 at 15:52
















2















I was troubled by the following code



Dim xTRrow as Integer
Dim xTitle as String
Dim xSht as Worksheet
xTRrow = xSht.Range(xTitle).Cells(1).Row


I wonder what the last line does. Especially, the .Row. In case as such, how do can I run the VBA code line by line to find out what a specific line of code does? I guess something is off with the code. I've tried to display xTRrow which should be an integer. But nothing jumps on the screen. I wonder what the last option .Row does.










share|improve this question

























  • .Row returns the row number of the specified cell

    – Brotato
    Nov 23 '18 at 15:52














2












2








2


0






I was troubled by the following code



Dim xTRrow as Integer
Dim xTitle as String
Dim xSht as Worksheet
xTRrow = xSht.Range(xTitle).Cells(1).Row


I wonder what the last line does. Especially, the .Row. In case as such, how do can I run the VBA code line by line to find out what a specific line of code does? I guess something is off with the code. I've tried to display xTRrow which should be an integer. But nothing jumps on the screen. I wonder what the last option .Row does.










share|improve this question
















I was troubled by the following code



Dim xTRrow as Integer
Dim xTitle as String
Dim xSht as Worksheet
xTRrow = xSht.Range(xTitle).Cells(1).Row


I wonder what the last line does. Especially, the .Row. In case as such, how do can I run the VBA code line by line to find out what a specific line of code does? I guess something is off with the code. I've tried to display xTRrow which should be an integer. But nothing jumps on the screen. I wonder what the last option .Row does.







excel vba excel-vba worksheet-function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 16:45









GSerg

59.6k15103225




59.6k15103225










asked Nov 23 '18 at 15:37









user10696147user10696147

133




133













  • .Row returns the row number of the specified cell

    – Brotato
    Nov 23 '18 at 15:52



















  • .Row returns the row number of the specified cell

    – Brotato
    Nov 23 '18 at 15:52

















.Row returns the row number of the specified cell

– Brotato
Nov 23 '18 at 15:52





.Row returns the row number of the specified cell

– Brotato
Nov 23 '18 at 15:52












2 Answers
2






active

oldest

votes


















1














In addition to using F8 to step through the code, you can use debug.print to display the values of relevant variables before and after the given line. That said as you use VBA, you will be able to recognize what object and method is. Assuming the code works fine and all variables and objects were dimmed and set properly:



xSht.Range(xTitle).Cells(1).Row


break down as follows:



xSht : variable containing a sheet (which sheet we don't know as that part of your code is missing in your question)



xTitle: probably the name of a named range (which range we don't know as that part of your code is missing in your question)



Cells(1): Cell no; 1 of the above mentionned named range



Row: the row of the cell in question



So xTRrow should be the row number of the cell in question. (BTW, it really should be Dimmed as Long as Excel can have more rows than Integer allows for






share|improve this answer































    0














    Row Trouble



    Description



    The variable 'xTRrow' is equal to the 'row' of the '1'st 'cell' of the 'range 'xTitle' in the worksheet 'xSht'. You can make it work by defining the missing data.



    The Code



    Option Explicit

    Sub RowTrouble()

    Dim xSht As Worksheet ' A Worksheet
    Dim xTitle As String ' A Range Address (or a Named Range)
    Dim xTRrow As Long ' A Row - rows are best declared as Long.

    ' ' Your code (not yet working)
    ' xTRrow = xSht.Range(xTitle).Cells(1).Row

    ' Define the range
    xTitle = "A1:D1"

    ' Create a reference to the worksheet with the name "Sheet1"
    Set xSht = ThisWorkbook.Worksheets("Sheet1")

    ' Your code working
    xTRrow = xSht.Range(xTitle).Cells(1).Row

    ' To display the result in the immediate window
    Debug.Print "The first row in my workbook's range (" & xTitle _
    & ") is equal to " & xTRrow & "."

    ' To display the result in a message box:
    MsgBox "The first row in my workbook's range (" & xTitle _
    & ") is equal to " & xTRrow & "."

    ' To display the result in the sheet:
    xSht.Range("A1") = "The first row in my workbook's range (" & xTitle _
    & ") is equal to " & xTRrow & "."

    End Sub


    How



    Open a new worksheet. Go to Visual Basic Editor and insert a new module into the worksheet. Copy/paste the example into it. Open the immediate window to be able to see the result. Run the code.



    Line by Line



    Too loop through the code line by line under Debug select Step Into or just use 'F8':



    enter image description here






    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',
      autoActivateHeartbeat: false,
      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%2f53449441%2frange-cells-row%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      In addition to using F8 to step through the code, you can use debug.print to display the values of relevant variables before and after the given line. That said as you use VBA, you will be able to recognize what object and method is. Assuming the code works fine and all variables and objects were dimmed and set properly:



      xSht.Range(xTitle).Cells(1).Row


      break down as follows:



      xSht : variable containing a sheet (which sheet we don't know as that part of your code is missing in your question)



      xTitle: probably the name of a named range (which range we don't know as that part of your code is missing in your question)



      Cells(1): Cell no; 1 of the above mentionned named range



      Row: the row of the cell in question



      So xTRrow should be the row number of the cell in question. (BTW, it really should be Dimmed as Long as Excel can have more rows than Integer allows for






      share|improve this answer




























        1














        In addition to using F8 to step through the code, you can use debug.print to display the values of relevant variables before and after the given line. That said as you use VBA, you will be able to recognize what object and method is. Assuming the code works fine and all variables and objects were dimmed and set properly:



        xSht.Range(xTitle).Cells(1).Row


        break down as follows:



        xSht : variable containing a sheet (which sheet we don't know as that part of your code is missing in your question)



        xTitle: probably the name of a named range (which range we don't know as that part of your code is missing in your question)



        Cells(1): Cell no; 1 of the above mentionned named range



        Row: the row of the cell in question



        So xTRrow should be the row number of the cell in question. (BTW, it really should be Dimmed as Long as Excel can have more rows than Integer allows for






        share|improve this answer


























          1












          1








          1







          In addition to using F8 to step through the code, you can use debug.print to display the values of relevant variables before and after the given line. That said as you use VBA, you will be able to recognize what object and method is. Assuming the code works fine and all variables and objects were dimmed and set properly:



          xSht.Range(xTitle).Cells(1).Row


          break down as follows:



          xSht : variable containing a sheet (which sheet we don't know as that part of your code is missing in your question)



          xTitle: probably the name of a named range (which range we don't know as that part of your code is missing in your question)



          Cells(1): Cell no; 1 of the above mentionned named range



          Row: the row of the cell in question



          So xTRrow should be the row number of the cell in question. (BTW, it really should be Dimmed as Long as Excel can have more rows than Integer allows for






          share|improve this answer













          In addition to using F8 to step through the code, you can use debug.print to display the values of relevant variables before and after the given line. That said as you use VBA, you will be able to recognize what object and method is. Assuming the code works fine and all variables and objects were dimmed and set properly:



          xSht.Range(xTitle).Cells(1).Row


          break down as follows:



          xSht : variable containing a sheet (which sheet we don't know as that part of your code is missing in your question)



          xTitle: probably the name of a named range (which range we don't know as that part of your code is missing in your question)



          Cells(1): Cell no; 1 of the above mentionned named range



          Row: the row of the cell in question



          So xTRrow should be the row number of the cell in question. (BTW, it really should be Dimmed as Long as Excel can have more rows than Integer allows for







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 15:52









          cybernetic.nomadcybernetic.nomad

          2,36021020




          2,36021020

























              0














              Row Trouble



              Description



              The variable 'xTRrow' is equal to the 'row' of the '1'st 'cell' of the 'range 'xTitle' in the worksheet 'xSht'. You can make it work by defining the missing data.



              The Code



              Option Explicit

              Sub RowTrouble()

              Dim xSht As Worksheet ' A Worksheet
              Dim xTitle As String ' A Range Address (or a Named Range)
              Dim xTRrow As Long ' A Row - rows are best declared as Long.

              ' ' Your code (not yet working)
              ' xTRrow = xSht.Range(xTitle).Cells(1).Row

              ' Define the range
              xTitle = "A1:D1"

              ' Create a reference to the worksheet with the name "Sheet1"
              Set xSht = ThisWorkbook.Worksheets("Sheet1")

              ' Your code working
              xTRrow = xSht.Range(xTitle).Cells(1).Row

              ' To display the result in the immediate window
              Debug.Print "The first row in my workbook's range (" & xTitle _
              & ") is equal to " & xTRrow & "."

              ' To display the result in a message box:
              MsgBox "The first row in my workbook's range (" & xTitle _
              & ") is equal to " & xTRrow & "."

              ' To display the result in the sheet:
              xSht.Range("A1") = "The first row in my workbook's range (" & xTitle _
              & ") is equal to " & xTRrow & "."

              End Sub


              How



              Open a new worksheet. Go to Visual Basic Editor and insert a new module into the worksheet. Copy/paste the example into it. Open the immediate window to be able to see the result. Run the code.



              Line by Line



              Too loop through the code line by line under Debug select Step Into or just use 'F8':



              enter image description here






              share|improve this answer






























                0














                Row Trouble



                Description



                The variable 'xTRrow' is equal to the 'row' of the '1'st 'cell' of the 'range 'xTitle' in the worksheet 'xSht'. You can make it work by defining the missing data.



                The Code



                Option Explicit

                Sub RowTrouble()

                Dim xSht As Worksheet ' A Worksheet
                Dim xTitle As String ' A Range Address (or a Named Range)
                Dim xTRrow As Long ' A Row - rows are best declared as Long.

                ' ' Your code (not yet working)
                ' xTRrow = xSht.Range(xTitle).Cells(1).Row

                ' Define the range
                xTitle = "A1:D1"

                ' Create a reference to the worksheet with the name "Sheet1"
                Set xSht = ThisWorkbook.Worksheets("Sheet1")

                ' Your code working
                xTRrow = xSht.Range(xTitle).Cells(1).Row

                ' To display the result in the immediate window
                Debug.Print "The first row in my workbook's range (" & xTitle _
                & ") is equal to " & xTRrow & "."

                ' To display the result in a message box:
                MsgBox "The first row in my workbook's range (" & xTitle _
                & ") is equal to " & xTRrow & "."

                ' To display the result in the sheet:
                xSht.Range("A1") = "The first row in my workbook's range (" & xTitle _
                & ") is equal to " & xTRrow & "."

                End Sub


                How



                Open a new worksheet. Go to Visual Basic Editor and insert a new module into the worksheet. Copy/paste the example into it. Open the immediate window to be able to see the result. Run the code.



                Line by Line



                Too loop through the code line by line under Debug select Step Into or just use 'F8':



                enter image description here






                share|improve this answer




























                  0












                  0








                  0







                  Row Trouble



                  Description



                  The variable 'xTRrow' is equal to the 'row' of the '1'st 'cell' of the 'range 'xTitle' in the worksheet 'xSht'. You can make it work by defining the missing data.



                  The Code



                  Option Explicit

                  Sub RowTrouble()

                  Dim xSht As Worksheet ' A Worksheet
                  Dim xTitle As String ' A Range Address (or a Named Range)
                  Dim xTRrow As Long ' A Row - rows are best declared as Long.

                  ' ' Your code (not yet working)
                  ' xTRrow = xSht.Range(xTitle).Cells(1).Row

                  ' Define the range
                  xTitle = "A1:D1"

                  ' Create a reference to the worksheet with the name "Sheet1"
                  Set xSht = ThisWorkbook.Worksheets("Sheet1")

                  ' Your code working
                  xTRrow = xSht.Range(xTitle).Cells(1).Row

                  ' To display the result in the immediate window
                  Debug.Print "The first row in my workbook's range (" & xTitle _
                  & ") is equal to " & xTRrow & "."

                  ' To display the result in a message box:
                  MsgBox "The first row in my workbook's range (" & xTitle _
                  & ") is equal to " & xTRrow & "."

                  ' To display the result in the sheet:
                  xSht.Range("A1") = "The first row in my workbook's range (" & xTitle _
                  & ") is equal to " & xTRrow & "."

                  End Sub


                  How



                  Open a new worksheet. Go to Visual Basic Editor and insert a new module into the worksheet. Copy/paste the example into it. Open the immediate window to be able to see the result. Run the code.



                  Line by Line



                  Too loop through the code line by line under Debug select Step Into or just use 'F8':



                  enter image description here






                  share|improve this answer















                  Row Trouble



                  Description



                  The variable 'xTRrow' is equal to the 'row' of the '1'st 'cell' of the 'range 'xTitle' in the worksheet 'xSht'. You can make it work by defining the missing data.



                  The Code



                  Option Explicit

                  Sub RowTrouble()

                  Dim xSht As Worksheet ' A Worksheet
                  Dim xTitle As String ' A Range Address (or a Named Range)
                  Dim xTRrow As Long ' A Row - rows are best declared as Long.

                  ' ' Your code (not yet working)
                  ' xTRrow = xSht.Range(xTitle).Cells(1).Row

                  ' Define the range
                  xTitle = "A1:D1"

                  ' Create a reference to the worksheet with the name "Sheet1"
                  Set xSht = ThisWorkbook.Worksheets("Sheet1")

                  ' Your code working
                  xTRrow = xSht.Range(xTitle).Cells(1).Row

                  ' To display the result in the immediate window
                  Debug.Print "The first row in my workbook's range (" & xTitle _
                  & ") is equal to " & xTRrow & "."

                  ' To display the result in a message box:
                  MsgBox "The first row in my workbook's range (" & xTitle _
                  & ") is equal to " & xTRrow & "."

                  ' To display the result in the sheet:
                  xSht.Range("A1") = "The first row in my workbook's range (" & xTitle _
                  & ") is equal to " & xTRrow & "."

                  End Sub


                  How



                  Open a new worksheet. Go to Visual Basic Editor and insert a new module into the worksheet. Copy/paste the example into it. Open the immediate window to be able to see the result. Run the code.



                  Line by Line



                  Too loop through the code line by line under Debug select Step Into or just use 'F8':



                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 23 '18 at 16:55

























                  answered Nov 23 '18 at 16:42









                  VBasic2008VBasic2008

                  2,9822416




                  2,9822416






























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449441%2frange-cells-row%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

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin