+ Reply to Thread
Results 1 to 5 of 5

Issue with selecting random blank cell in range

  1. #1
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Exclamation Issue with selecting random blank cell in range

    Hi All,

    I'm having an issue with selecting a blank cell at random in a specified range. For some reason it is returning a cell that is out of the range given to the function or it is giving an error back. I have the following.

    Please Login or Register  to view this content.
    Thanks in advance for any help!

  2. #2
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Issue with selecting random blank cell in range

    Update I have thought of a work around using collections... if anyone can help make this more efficient however that would be brilliant!

    Please Login or Register  to view this content.
    !If all your troubles are solved, then so is the thread. Show this by marking it so using thread tools at the top of the page.
    If I helped do this, then please show your appreciation by awarding rep points.
    <------ Button for that is over there

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Issue with selecting random blank cell in range

    Can you attach a short Excel sample to be sure we are working on the same data ..!
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Issue with selecting random blank cell in range

    The code will only really work when the gamezone is completely empty. At the point the range is C4:I10.
    once you populate the gamezone the range returned by specialcell blank is a non contiguous one. The although the random number is within the count of cells of that non contiguous range
    the .Cells(x) reference is only based on the first area of the non contiguous range. So for some random values this will be in that first area, for others in will be beyond
    the first area but within the gamezone area, so it appears okay. for other values it will be outside the gamezone completely.

    here is an example. range C4:I10 is empty except for E4.
    The range address is $C$4:$D$4,$F$4:$I$4,$C$5:$I$10

    If your random number is 3 then the actual cells returned is $C$5 and not $F$4

    Here is some code that stores empty cells and then random selects one of them. Once selected it is removed from the collection.
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Issue with selecting random blank cell in range

    Thank you for your help. It seems we had a similar idea in the end! Thank you for explaining the reason for the error!

+ 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. Selecting certain random cells from a range
    By nekmat97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2018, 08:36 PM
  2. [SOLVED] Selecting Range upto first blank cell in a column
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2016, 04:59 PM
  3. Selecting dynamic range with first blank cell
    By DCRAIG3389 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2015, 05:11 PM
  4. [SOLVED] Any suggestion on my range selecting issue?
    By kaxxp in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-22-2014, 05:39 PM
  5. Selecting random cell with color
    By Blokeman in forum Excel General
    Replies: 5
    Last Post: 02-19-2013, 07:25 AM
  6. Selecting the next blank cell in a range
    By camcrazy08 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2007, 12:40 PM
  7. Selecting the first non blank cell in Range
    By VBA Noob in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-24-2006, 02:39 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