Method 'Range' of object '_Worksheet' failed in Excel VBA, halp?











up vote
1
down vote

favorite












Okay, let me start by saying I am a noob at this. I'm following this step-by-step video, and I still found a way to mess it up somehow. I've tried reading related questions, but I don't really know much about VBA to make sense of the answers.



Basically, I'm trying (and failing) to create an "Employee Manager." At around 9:44 of the video, the narrator said we'll need to create a macro to hide and show specific cells depending on what tab we click on.



Here is my code for Sheet1:



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("E4:H4")) Is Nothing Then
Range("B2").Value = Target.Column
Range("F2").Select
SwitchHTabs
End If
End Sub


And I have this code under modules, with the macro named SwitchHTabs:



Option Explicit

Sub SwitchHTabs()
Dim SelCol As Long
Dim FirstRow As Long

SelCol = ActiveCell.Column

With Sheet1
.Range("5:84").EntireRow.Hidden = True
FirstRow = 5 + ((SelCol - 5) * 20)
.Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'This is the line with the error
End With
End Sub


This error pops up when I try to run the code:
enter image description here



And when I click Debug, it highlights this line of code:
enter image description here



Where'd I mess up? I'm using Excel 2016. Thank you!










share|improve this question









New contributor




aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    1
    down vote

    favorite












    Okay, let me start by saying I am a noob at this. I'm following this step-by-step video, and I still found a way to mess it up somehow. I've tried reading related questions, but I don't really know much about VBA to make sense of the answers.



    Basically, I'm trying (and failing) to create an "Employee Manager." At around 9:44 of the video, the narrator said we'll need to create a macro to hide and show specific cells depending on what tab we click on.



    Here is my code for Sheet1:



    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("E4:H4")) Is Nothing Then
    Range("B2").Value = Target.Column
    Range("F2").Select
    SwitchHTabs
    End If
    End Sub


    And I have this code under modules, with the macro named SwitchHTabs:



    Option Explicit

    Sub SwitchHTabs()
    Dim SelCol As Long
    Dim FirstRow As Long

    SelCol = ActiveCell.Column

    With Sheet1
    .Range("5:84").EntireRow.Hidden = True
    FirstRow = 5 + ((SelCol - 5) * 20)
    .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'This is the line with the error
    End With
    End Sub


    This error pops up when I try to run the code:
    enter image description here



    And when I click Debug, it highlights this line of code:
    enter image description here



    Where'd I mess up? I'm using Excel 2016. Thank you!










    share|improve this question









    New contributor




    aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Okay, let me start by saying I am a noob at this. I'm following this step-by-step video, and I still found a way to mess it up somehow. I've tried reading related questions, but I don't really know much about VBA to make sense of the answers.



      Basically, I'm trying (and failing) to create an "Employee Manager." At around 9:44 of the video, the narrator said we'll need to create a macro to hide and show specific cells depending on what tab we click on.



      Here is my code for Sheet1:



      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Not Intersect(Target, Range("E4:H4")) Is Nothing Then
      Range("B2").Value = Target.Column
      Range("F2").Select
      SwitchHTabs
      End If
      End Sub


      And I have this code under modules, with the macro named SwitchHTabs:



      Option Explicit

      Sub SwitchHTabs()
      Dim SelCol As Long
      Dim FirstRow As Long

      SelCol = ActiveCell.Column

      With Sheet1
      .Range("5:84").EntireRow.Hidden = True
      FirstRow = 5 + ((SelCol - 5) * 20)
      .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'This is the line with the error
      End With
      End Sub


      This error pops up when I try to run the code:
      enter image description here



      And when I click Debug, it highlights this line of code:
      enter image description here



      Where'd I mess up? I'm using Excel 2016. Thank you!










      share|improve this question









      New contributor




      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Okay, let me start by saying I am a noob at this. I'm following this step-by-step video, and I still found a way to mess it up somehow. I've tried reading related questions, but I don't really know much about VBA to make sense of the answers.



      Basically, I'm trying (and failing) to create an "Employee Manager." At around 9:44 of the video, the narrator said we'll need to create a macro to hide and show specific cells depending on what tab we click on.



      Here is my code for Sheet1:



      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Not Intersect(Target, Range("E4:H4")) Is Nothing Then
      Range("B2").Value = Target.Column
      Range("F2").Select
      SwitchHTabs
      End If
      End Sub


      And I have this code under modules, with the macro named SwitchHTabs:



      Option Explicit

      Sub SwitchHTabs()
      Dim SelCol As Long
      Dim FirstRow As Long

      SelCol = ActiveCell.Column

      With Sheet1
      .Range("5:84").EntireRow.Hidden = True
      FirstRow = 5 + ((SelCol - 5) * 20)
      .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'This is the line with the error
      End With
      End Sub


      This error pops up when I try to run the code:
      enter image description here



      And when I click Debug, it highlights this line of code:
      enter image description here



      Where'd I mess up? I'm using Excel 2016. Thank you!







      excel vba






      share|improve this question









      New contributor




      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 10 at 14:25









      Chronocidal

      2,4801216




      2,4801216






      New contributor




      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 10 at 14:20









      aiseaisebb

      84




      84




      New contributor




      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      aiseaisebb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Compare your two Range lines in that sub:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'Doesn't Work


          For the sake of argument, let's assume that FirstRow is 1, and then process that second line of code:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range("1.20").EntireRow.Hidden = False 'Doesn't Work


          Hopefully it is now easier to see that you have used a Full-Stop in place of a Colon.



          (As an aside - you can use .Rows("5:84").Hidden instead to remove the need for .EntireRow)






          share|improve this answer





















          • O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
            – aiseaisebb
            Nov 10 at 14:33











          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
          });


          }
          });






          aiseaisebb is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239858%2fmethod-range-of-object-worksheet-failed-in-excel-vba-halp%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Compare your two Range lines in that sub:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'Doesn't Work


          For the sake of argument, let's assume that FirstRow is 1, and then process that second line of code:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range("1.20").EntireRow.Hidden = False 'Doesn't Work


          Hopefully it is now easier to see that you have used a Full-Stop in place of a Colon.



          (As an aside - you can use .Rows("5:84").Hidden instead to remove the need for .EntireRow)






          share|improve this answer





















          • O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
            – aiseaisebb
            Nov 10 at 14:33















          up vote
          1
          down vote



          accepted










          Compare your two Range lines in that sub:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'Doesn't Work


          For the sake of argument, let's assume that FirstRow is 1, and then process that second line of code:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range("1.20").EntireRow.Hidden = False 'Doesn't Work


          Hopefully it is now easier to see that you have used a Full-Stop in place of a Colon.



          (As an aside - you can use .Rows("5:84").Hidden instead to remove the need for .EntireRow)






          share|improve this answer





















          • O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
            – aiseaisebb
            Nov 10 at 14:33













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Compare your two Range lines in that sub:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'Doesn't Work


          For the sake of argument, let's assume that FirstRow is 1, and then process that second line of code:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range("1.20").EntireRow.Hidden = False 'Doesn't Work


          Hopefully it is now easier to see that you have used a Full-Stop in place of a Colon.



          (As an aside - you can use .Rows("5:84").Hidden instead to remove the need for .EntireRow)






          share|improve this answer












          Compare your two Range lines in that sub:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range(FirstRow & "." & FirstRow + 19).EntireRow.Hidden = False 'Doesn't Work


          For the sake of argument, let's assume that FirstRow is 1, and then process that second line of code:



          .Range("5:84").EntireRow.Hidden = True 'Works
          .Range("1.20").EntireRow.Hidden = False 'Doesn't Work


          Hopefully it is now easier to see that you have used a Full-Stop in place of a Colon.



          (As an aside - you can use .Rows("5:84").Hidden instead to remove the need for .EntireRow)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 14:26









          Chronocidal

          2,4801216




          2,4801216












          • O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
            – aiseaisebb
            Nov 10 at 14:33


















          • O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
            – aiseaisebb
            Nov 10 at 14:33
















          O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
          – aiseaisebb
          Nov 10 at 14:33




          O. M. F. G. I can't believe I missed that, you're a lifesaver! Thank you, thank you, thank you!!!
          – aiseaisebb
          Nov 10 at 14:33










          aiseaisebb is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          aiseaisebb is a new contributor. Be nice, and check out our Code of Conduct.













          aiseaisebb is a new contributor. Be nice, and check out our Code of Conduct.












          aiseaisebb is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239858%2fmethod-range-of-object-worksheet-failed-in-excel-vba-halp%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Jo Brand