+ Reply to Thread
Results 1 to 8 of 8

Column number reference using cell reference

  1. #1
    Registered User
    Join Date
    06-02-2015
    Location
    B
    MS-Off Ver
    2013
    Posts
    5

    Column number reference using cell reference

    Hi all,

    I have created a basic macro which hides columns before and after a specified range. I have calculated the column numbers from a user specified date in excel and want to use these cell references in my VBA code to hide the columns.

    For example:

    Cell B9's formular tells me the users date starts at column 37.
    Cell B10's formular tells me the users date ends at column 42.

    Becuase these dates change I need to reference cells B9 and B10 and not the column numbers 37 and 42.

    So I want to hide colomns 4:B9 and B10:55.

    My code keeps failing with error "type mismatch".



    Please Login or Register  to view this content.
    Any help would be great!
    Last edited by FDibbins; 06-02-2015 at 10:54 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Column number reference using cell reference

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I have added the for you - this time
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    06-02-2015
    Location
    B
    MS-Off Ver
    2013
    Posts
    5

    Re: Column number reference using cell reference

    My Apologies. Thanks for your help.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Column number reference using cell reference

    No problem, if you dont get told, you wont know

  5. #5
    Registered User
    Join Date
    06-02-2015
    Location
    B
    MS-Off Ver
    2013
    Posts
    5

    Re: Column number reference using cell reference

    Bump. Does anyone have any thoughts?

  6. #6
    Registered User
    Join Date
    06-02-2015
    Location
    B
    MS-Off Ver
    2013
    Posts
    5

    Re: Column number reference using cell reference

    So I have tried another approach with this question. I have attached the spreadsheet in question. In the 2015 tab I already have some "Hide Quarter" buttons which hide/unhide everything but the current quarter. They work. It's the code for the buttons below which I can't get to work.

    As you can see I am intending the user to enter in a project start and end date and I want to see all columns outside these dates hidden. So far this is where I am with the code but I keep getting a "Compile Error: Next without for". From what i can see I have the next and for's but I get a bit out of my depth there.

    Please Login or Register  to view this content.
    Can someone provide some feedback?
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: Column number reference using cell reference

    The IF / THEN ELSE statement in each FOR / NEXT loop is missing its END IF.

    Adding ENF IF just before NEXT should prevent the error (the compiler gets to NEXT before the IF decision has ended, hence the obscure error message.)

    Hopt this helps.
    - Stu

  8. #8
    Registered User
    Join Date
    06-02-2015
    Location
    B
    MS-Off Ver
    2013
    Posts
    5

    Re: Column number reference using cell reference

    OK thanks Stu that helped. It's still producing errors. This time "method 'Range' of object '_worksheet' failed".

    Please Login or Register  to view this content.
    And the GetColumnLetter_ByInteger code:

    Please Login or Register  to view this content.
    Anyone have any ideas? I didn't imagine this would be such technical code. All I wanted was to his columns outside a users specified range. I'm not sure my code is even on the right path...
    Attached Files Attached Files

+ 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. how to reference cell value from column number and row number
    By jed38 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-11-2015, 07:37 PM
  2. Replies: 1
    Last Post: 02-11-2015, 01:56 PM
  3. [SOLVED] VLOOKUP to reference cell, not column number
    By Prodschdler in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-18-2013, 02:27 PM
  4. Go to a cell in column, based on a reference number
    By Joshua@work in forum Excel General
    Replies: 5
    Last Post: 06-30-2010, 07:28 PM
  5. Replies: 1
    Last Post: 02-03-2006, 12:00 PM

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