+ Reply to Thread
Results 1 to 6 of 6

vba question on range

  1. #1
    Registered User
    Join Date
    12-11-2013
    Location
    nyc
    MS-Off Ver
    M365 V2311
    Posts
    65

    vba question on range

    Hi Friends,

    I wanted to hide the rows if all the columns from C:R is = to zero but i also wanted to start this macro from row 20 and going forward.

    Please see code below and let me know what's wrong. Thanks, Excel forum rocks.

    Public Sub Hiderows()
    Dim LRow As Integer
    Dim i As Integer
    LRow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 To LRow
    If Cells(i, "B") = 0 And Cells(i, "C") = 0 And Cells(i, "D") = 0 And Cells(i, "E") = 0 And Cells(i, "F") = 0 And Cells(i, "GC") = 0 And Cells(i, "H") = 0 And Cells(i, "I") = 0 And Cells(i, "J") = 0 And Cells(i, "K") = 0 And Cells(i, "L") = 0 And Cells(i, "M") = 0 And Cells(i, "N") = 0 And Cells(i, "O") = 0 And Cells(i, "P") = 0 And Cells(i, "Q") = 0 And Cells(i, "R") = 0 And Cells(i, "S") = 0 Then
    Rows(i).EntireRow.Hidden = True
    End If
    Next
    End Sub

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: vba question on range

    Hello and welcome to the forum,

    As per forum rules, please use code tags when you post code.

    Here's a proposal for your question :
    This will hide rows if cells C to R = 0

    Please Login or Register  to view this content.
    Note that you say C:R = 0 in your first phrase but it is from B to S in your code ???
    Adapt the code accordingly.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    12-11-2013
    Location
    nyc
    MS-Off Ver
    M365 V2311
    Posts
    65

    Re: vba question on range

    Ah, i see.

    A continuation of the question would be what if i want to start this macro from row 20 to row 25 then stop and start from row 30 to the end.

    Your help is much appreciated.

    Thanks you so much.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba question on range

    Please Login or Register  to view this content.
    Or you could do 2 loops

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: vba question on range

    Hi stnkynts,

    I guess you meant :
    (For i = 20 to Lrow instead of i = 20 to 25)

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba question on range

    @GC Excel. That is correct. Good catch and thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 07-26-2013, 03:38 PM
  2. [SOLVED] Question regarding conditional format question that covers two range criteria
    By lilsnoop in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-06-2013, 12:32 PM
  3. if range question
    By gr4nt in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-19-2007, 02:32 PM
  4. Question on Range in VB
    By leon22 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2005, 07:39 AM
  5. Range Question / error 1004: method Range of object Worksheet has failed
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2005, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1