+ Reply to Thread
Results 1 to 2 of 2

VBA macro to hide/unhide columns depending on button text

Hybrid View

namso1902 VBA macro to hide/unhide... 03-09-2013, 07:53 AM
event21 Re: VBA macro to hide/unhide... 03-09-2013, 08:12 AM
  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2007
    Posts
    8

    VBA macro to hide/unhide columns depending on button text

    I am trying to create a button with a macro that will hide columns depending on the text value of that button. There are syntax errors which I cannot solve:

    Formula: copy to clipboard
    Sub View_Stt()
    '
    ' View_Stt Macro
    '

    If CustAccount.Shapes("View_Stt").Text = "View statement" Then
    Columns("J:P").Select
    Selection.EntireColumn.Hidden = False
    Range("B11").Select
    CustAccount.Shapes("View_Stt").Text = "Hide statement"
    ElseIf CustAccount.Shapes("View_Stt").Text = "Hide statement" Then
    Columns("J:P").Select
    Selection.EntireColumn.Hidden = True
    Range("B11").Select
    CustAccount.Shapes("View_Stt").Text = "View statement"
    End If
    End Sub


    The statement is the totals and VAT summary sections plus the transactions list. Hiding these sections will show just the account. It could also be that I have not referred to the name of the button correctly, but if I have would not know how to find the actual name of it.

    I have attached the spreadsheet to this post. The sheet in question is the "CustAccount" sheet and the button has "View statement" text on it.

    Any help would be greatly appreciated and I would be happy to clarify my problem further if required.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: VBA macro to hide/unhide columns depending on button text

    Hi -

    try
    Sub View_Stt()
    '
    ' View_Stt Macro
    '
    
        If Sheets("CustAccount").Shapes("Button 3").TextFrame.Characters.Text = "View statement" Then
            Columns("J:P").Select
            Selection.EntireColumn.Hidden = False
            Range("B11").Select
            Sheets("CustAccount").Shapes("Button 3").TextFrame.Characters.Text = "Hide statement"
        ElseIf Sheets("CustAccount").Shapes("Button 3").TextFrame.Characters.Text = "Hide statement" Then
            Columns("J:P").Select
            Selection.EntireColumn.Hidden = True
            Range("B11").Select
            Sheets("CustAccount").Shapes("Button 3").TextFrame.Characters.Text = "View statement"
        End If
    End Sub
    event

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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