Results 1 to 9 of 9

Hiding a Relative Range of Columns with VBA using R1C1 Format

Threaded View

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    USA, Earth
    MS-Off Ver
    Excel 2010
    Posts
    16

    Question Hiding a Relative Range of Columns with VBA using R1C1 Format

    Hello All,

    I have searched the forums and Google and found inconclusive or merely partial implementations to hiding a range of columns (or rows) using R1C1 format in Excel VBA. The goal of this code is to have a set of rows hidden depending on the result read-in by a Case statement. The Case statement works well on its own, so for the sake of clarity and simplification it has been removed from the code below.

    Using Excel 2010, the following code portion is from my original, working version that would need to be changed manually for a moving range:

    
    Option Compare Text         '   Lets:   A=a, B=b, ... Z=z
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' Define Variables ' ========================
    Dim WS01__sheet As Worksheet
    '.... '.... ' Hide Columns: '------------------
    WS01__sheet.Columns("N:Y").EntireColumn.Hidden = True WS01__sheet.Columns("Z").EntireColumn.Hidden = True
    End Sub
    To achieve this, I have attempted the following:

    
    Option Compare Text         '   Lets:   A=a, B=b, ... Z=z
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' Define Variables ' ========================
    Dim Column_set_01__orig As Integer Dim WS01__sheet As Worksheet
    'Define Variables: '--------------------
    Column_set_01__orig = 10
    '.... '.... ' Hide Columns: '------------------
    'Attempt 1: WS01__sheet.Range(Cells(1, (Column_set_01__orig + 4)), Cells(1, (Column_set_01__orig+ 16))).EntireColumn.Hidden = True 'Attempt 2: (non-preferred method) ' WS01__sheet.Range(Cells(1, (Column_set_01__orig + 4)), Cells(1, (Column_set_01__orig + 16))).Select ' Selection.EntireColumn.Hidden = True
    End Sub

    May I please get some assistance with this issue? I am not sure what is being done incorrectly, but I would also like to know why each method does not work, instead of only a quick fix so I can learn. From what I understand, using ".select" is wasted computation time, particularly if this gets to be a rather large, actively running project.

    Thanks you all in advance.
    Last edited by Sarvazad; 12-03-2014 at 05:42 PM. Reason: Minor definition was forgotten with code block 2

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Convert Range of a Pivot Table to R1C1 format
    By Gorilla in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-29-2013, 09:49 AM
  2. [SOLVED] Hiding 3 columns using R1C1 format
    By jartzh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2012, 11:54 AM
  3. Using R1C1 Format to Define Print Range
    By PosseJohn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2011, 03:10 AM
  4. Updating Named Range when new contact is added using R1C1 format with a variable
    By sgreni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2010, 01:40 PM
  5. Range with R1C1 format
    By one8421 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2009, 07:01 AM

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