+ Reply to Thread
Results 1 to 4 of 4

Trying to add a second range in a macro

  1. #1
    Forum Contributor
    Join Date
    11-22-2003
    Location
    Newport, Rhode Island
    MS-Off Ver
    2021
    Posts
    154

    Trying to add a second range in a macro

    Hi All, Using Excel 2013
    I'm running a macro that hides rows that are greater than today's date in Range I29:I79.
    The macro below runs the macro correctly. I want to add a second range in the same macro I82:I132 but haven't got it to work.
    I added in the line Set MyRange = Range("I29:I79", ("I82:i132") but receive an error message saying invalid reference.
    Any help trying to get the two ranges to work in the same macro, thanks.
    Mike






    Sub Hide_Dates()
    Dim MyRange As Range, c As Range
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Set MyRange = Range("i29:i79")
    MyRange.EntireRow.Hidden = False
    For Each c In MyRange
    If IsDate(c.Value) And c.Value > Date Then
    c.EntireRow.Hidden = True
    End If
    Next
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Trying to add a second range in a macro

    Hi, Mike,

    please use code-tags to display your procedures.

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    11-22-2003
    Location
    Newport, Rhode Island
    MS-Off Ver
    2021
    Posts
    154

    Re: Trying to add a second range in a macro

    Thanks so much HaHoBe, I did quotes instead of the code tags by mistake. Macro runs perfectly.

    Mike

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Trying to add a second range in a macro

    Another alternative with less interaction between VBA and the spreadsheet, no real need to turn off calculation and screenupdating:

    Please Login or Register  to view this content.
    Cheers, berlan
    Last edited by berlan; 06-15-2014 at 03:25 PM.

+ 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. [SOLVED] Macro to hide entire columns within range if cells within range are blank
    By graphicgoose in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 08:26 PM
  2. excel 2007 macro need to have variable range of rows rather than fixed range
    By JW1028 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2013, 02:45 PM
  3. Macro stores Active Sheet range but I need it to find a new range each time it runs
    By jaroesner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2013, 08:00 AM
  4. Replies: 0
    Last Post: 10-23-2012, 01:50 AM
  5. Change range of cells within VBA macro and copy and paste to fixed cell range
    By Mannyny in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-20-2012, 11:51 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