+ Reply to Thread
Results 1 to 6 of 6

How to properly qualify a range

  1. #1
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    How to properly qualify a range

    Hi,

    I have written some code to export queries from access into excel and then apply some formatting.

    Please Login or Register  to view this content.
    Now this works perfectly fine but I know it isn't quite good practice.

    In the first with ws1 section I understand that the lastrow = ...part works because it is in the currently active sheet. And then later down I have had to put some formatting into the If intcurrent = 2 and If intcurrent = 3 sections because I get an error if I bring them up under the with ws2 and with ws3 sections and use the lastrow reference again because, one it is referencing the first sheet, and 2 because there is no object properly set.

    So my question is how can I neaten this up and what is the code for properly setting references to the ranges. Ideally i'd define the range Range("A1").End(xlDown).Row for each worksheet.

    Thanks in advance!
    Last edited by ungers; 10-27-2013 at 12:51 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: How to properly qualify a range

    Please Login or Register  to view this content.

    Should be:

    Please Login or Register  to view this content.

    The dot links the range to ws1


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: How to properly qualify a range

    Well that's what I thought...

    If I do that and then add bring up into With ws2 the line to set the custom invoice number format like this:
    Please Login or Register  to view this content.
    Then it throws a run time error 1004 application defined or object defined error and highlights this:
    .Range(Range("B2"), Range("B" & lastrow)).NumberFormat = "\D\U\A\L0##\/\/###"

    It does this if I bring anything from the looped section up into the individual worksheets.

    Curiously I have another export with identical code that doesn't do this...does it matter that this is the second pub on the page?

    I am not experienced enough to work this out and have tried lots of combinations of declaring the lastrow reference and assume it is me making a mistake in that respect!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: How to properly qualify a range

    Please Login or Register  to view this content.
    Look at it again ... what is missing? A clue: same answer as last time.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: How to properly qualify a range

    Thank You TMS!

    I think because my first workbook didn't throw the same errors I missed that bit on the learning curve!!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: How to properly qualify a range

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. text to pre-qualify from a list
    By rdyteves in forum Excel General
    Replies: 2
    Last Post: 12-12-2011, 08:11 PM
  2. Checking 3+ ranges to qualify a value
    By Masrim in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-28-2011, 04:36 PM
  3. function to qualify plain text rows before importing (xlFixedWidth)
    By reteptnarg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2010, 08:01 PM
  4. How to create a table to qualify a qty discount in exel
    By 1image in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 10-12-2005, 11:05 AM
  5. Query on Date range does not qualify the Year
    By Malcolm Makin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-23-2005, 02:05 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