+ Reply to Thread
Results 1 to 7 of 7

Macro - Unhide formula not migrating

Hybrid View

  1. #1
    Registered User
    Join Date
    10-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    4

    Macro - Unhide formula not migrating

    I am creating a form which requires one row at a time to become unhidden via the use of a macro attached to a button.

    The table has separate sections in which I will need to use this option.

    I have the formula working for the first section, which I will refer to as section A, this spans from row 23 to row 50. However when I create another button and change the macro for the next section (Section B - Rows 56 to 83) and click the button it still unhides rows for the first table rather than the lower one.

    Here are the macros I am using;


    Section A
    Sub UnhideNext()

    Dim mRange(0.5) As Range

    For x = b23 To b50
    Set mRange(x) = ActiveSheet.Range(Cells((x * 23) + 1, 1), Cells((x + 50) * 50, 23))
    Next

    For x = 0 To UBound(mRange())
    For Each mRow In mRange(0).Rows
    If mRow.Hidden = True Then
    mRow.Hidden = False
    Exit For
    End If
    Next
    Next

    End Sub
    Section B
    Sub UnhideNext()

    Dim mRange(0.5) As Range

    For x = a56 To a83
    Set mRange(x) = ActiveSheet.Range(Cells((x * 56) + 1, 1), Cells((x + 83) * 83, 56))
    Next

    For x = 0 To UBound(mRange())
    For Each mRow In mRange(0).Rows
    If mRow.Hidden = True Then
    mRow.Hidden = False
    Exit For
    End If
    Next
    Next

    End Sub
    Any advice on this would be greatly appreciated

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro - Unhide formula not migrating

    Why not:
    Sub unhidenext1()
    Rows("23:50").hidden = true
    end sub
    sub unhidenext2()
    rows("56:83").hiden = true
    end sub
    Looks like your issue could be that both macros have the same name?

  3. #3
    Registered User
    Join Date
    10-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro - Unhide formula not migrating

    Quote Originally Posted by yudlugar View Post
    Why not:
    Sub unhidenext1()
    Rows("23:50").hidden = true
    end sub
    sub unhidenext2()
    rows("56:83").hiden = true
    end sub
    Looks like your issue could be that both macros have the same name?
    You'll have to forgive me as I am new to this, how would I go about changing the names of these?

    I have already renames them to 'Module 4' and 'Module 5' as seen below, but one appears differently.

    See image:

    0e4eIFU.png
    Last edited by Teasle; 10-02-2013 at 09:45 AM. Reason: more info added

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro - Unhide formula not migrating

    You name your macro with the sub command:
    Sub UnhideNext()
    If you have two macros with the same name this will create an error

  5. #5
    Registered User
    Join Date
    10-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro - Unhide formula not migrating

    Thanks so far. I have renamed the macros as follows however they still unhide columns in the same area:

    xl.png

  6. #6
    Registered User
    Join Date
    10-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro - Unhide formula not migrating

    If anyone could help me further that'd be great - this is urgent!

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro - Unhide formula not migrating

    What are you actually trying to do? Looking through your code
    sub UnhideNext()
    
    Dim mRange(0.5) As Range
    
    For x = b23 To b50 'b23 and b50 will be set to variant variables. As you have not defined them they will be =0
    Set mRange(x) = ActiveSheet.Range(Cells((x * 23) + 1, 1), Cells((x + 50) * 50, 23))
    Next ' this will loop through repeatedly and only set myrange to mrange(b50), 
    'the previous iterations of the loop will be overwritten. As b50 = 0, x = 0, 
    'therefore cells(1,1),cells(250,23) will be selected. in your other code a83 
    'will also be 0 and therefore will select the same cells.
    
    'the below section can be replaced with mRange.cells.entirerow.hidden = true
    For x = 0 To UBound(mRange())
    For Each mRow In mRange(0).Rows
    If mRow.Hidden = True Then
    mRow.Hidden = False
    Exit For
    End If
    Next
    Next
    
    End Sub

+ 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: 3
    Last Post: 12-13-2013, 03:37 PM
  2. Macro Help - Migrating Data from one workbook to another
    By crayhons in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-26-2013, 10:01 AM
  3. [SOLVED] Apply formula via macro to unhide row only
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2013, 08:43 AM
  4. Macro to unhide sheets IF macro is enabled and hard drive serial # match list of HD#
    By nikolaikolev in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2011, 01:50 PM
  5. Replies: 2
    Last Post: 03-05-2006, 11:40 PM

Tags for this Thread

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