Results 1 to 5 of 5

Selecting a variable number of columns

Threaded View

Albathien Selecting a variable number... 07-11-2012, 08:40 AM
arlu1201 Re: Selecting a variable... 07-11-2012, 09:17 AM
MarvinP Re: Selecting a variable... 07-11-2012, 09:28 AM
Albathien Re: Selecting a variable... 07-11-2012, 12:48 PM
Albathien Re: Selecting a variable... 07-14-2012, 11:05 AM
  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    3

    Selecting a variable number of columns

    I have a value on one sheet that when I change it, I would like it to hide a number of columns on another sheet.
    This is what I have so far
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer
    
    If Target.Address = "$C$34" Then
        i = Target.Value
        Sheets("Cost Savings").Activate
        ActiveSheet.Range("C:N").EntireColumn.Hidden = False
        ActiveSheet.Range(Cells(1, i + 2), Cells(1, 14)).EntireColumn.Hidden = True
    End If
    End Sub
    On Sheet1 - I have 12 columns "C to N". When I change the value of C34 on sheet2, then it should hide the 'remaining' number of columns on sheet1. i.e if I enter "3" into C34 on Sheet2, then columns C,D and E should remain visible, columns F - N should be hidden on Sheet1.

    I am getting error code '1004': Application-defined or object-defined error. for the red line of code.

    I've tried these alternatives

    Range("F:N") works
    Range(Cells(1, 6), Cells(1, 14)) doesn't work
    Range(Columns(6), Columns(14)) doesn't work

    I'ld appreciate any help anyone could offer on this.
    Thanks in advance
    Last edited by Albathien; 07-12-2012 at 09:04 AM. Reason: Clarity

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