+ Reply to Thread
Results 1 to 11 of 11

Select range of cells based on 1 cell value

  1. #1
    Registered User
    Join Date
    01-12-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    7

    Question Select range of cells based on 1 cell value

    I am trying to figure out a VBA to select range of cells in same row based on a value in a cell.
    Example: let's say A1 cell has "5" as the cells value then it will select the 5 adjacent cells (B1:F1) and enter "OK" to those 5 cells Then then VBA will keep checking A2 on wards for value n do the same as above but if it found first blank cell in column A then the VBA stop

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Select range of cells based on 1 cell value

    How about this...

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    01-12-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    7

    Re: Select range of cells based on 1 cell value

    thanks alot....it works....
    I try to make it work with worksheet change event but it just don't work or crash the excel
    any idea why?

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Select range of cells based on 1 cell value

    I'm guessing you are saying, as you enter data in column A you want the macro to fire?

    Please Login or Register  to view this content.
    Place this code in the sheet module
    Last edited by jeffreybrown; 12-02-2019 at 10:49 AM.

  5. #5
    Registered User
    Join Date
    01-12-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    7

    Re: Select range of cells based on 1 cell value

    Quote Originally Posted by jeffreybrown View Post
    I'm guessing you are saying, as you enter data in column A you want the macro to fire?
    either I key in data manually or the data in column A is being changed with some formula in other cell

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Select range of cells based on 1 cell value

    Quote Originally Posted by dairin View Post
    either I key in data manually or the data in column A is being changed with some formula in other cell
    You can't have it both ways. Manually entered data and data changed via a formula are two different actions.

    Well, maybe you can have it both ways, just not sure how to go about it. In the end, you need to map out the process so we can build a solution to fit.

  7. #7
    Registered User
    Join Date
    01-12-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    7

    Re: Select range of cells based on 1 cell value

    ok then let me try myself first....thanks alot
    just 1 last question.....how to ensure that if the number that I enter is smaller than the previous number then it will delete the extra "OK"
    example: 1 enter 5 at first then it shows 5 "OK" but when I enter 3 in the next round, it will delete 2 "OK" and just show 3 "OK"

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Select range of cells based on 1 cell value

    What if you just clear a certain number of cells? This will clear 100 cells to the right of the target cell. Column A.

    Would this work?

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-12-2015
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    7

    Re: Select range of cells based on 1 cell value

    It works like a charm.....thanks alot......
    Last edited by jeffreybrown; 12-02-2019 at 11:08 AM. Reason: Please don't use full quotes!

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Select range of cells based on 1 cell value

    You are very welcome and thanks for the feedback.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Select range of cells based on 1 cell value

    Note:

    Just in case you don't want to go all the way out to 100 column since you may have information out there not to be messed with, try this on a copy of your data

    Please Login or Register  to view this content.

+ 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. Using offset function to select a range of cells based on active cell location
    By laxminarayana in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-25-2017, 07:49 AM
  2. [SOLVED] Select range of cells based on another 2 cells values
    By Ravenous in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-11-2017, 09:33 AM
  3. Replies: 2
    Last Post: 02-06-2016, 10:19 AM
  4. [SOLVED] Select a range of cells based on row count
    By bdrilling33 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2014, 06:07 PM
  5. Select Range In Column Based On Two Different Cells
    By Regular_Joe in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 05-30-2014, 11:47 AM
  6. select range of cells based on value in a cell
    By vinz3nt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2014, 01:33 PM
  7. [SOLVED] how can I select a range of cells based on a value of a cell?
    By grigoras victor in forum Excel General
    Replies: 1
    Last Post: 06-26-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