+ Reply to Thread
Results 1 to 11 of 11

VBA select cell with a specific value and all cells below until blank

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    VBA select cell with a specific value and all cells below until blank

    I would like to use a macro for a new but similar document I get each week. In the document there is a section with a label that I want to select just that section. It is divided by a blank row above and a total and blank row below. The total number in row 718 equals the number of rows in that section, so I may be able to trim that number and use it as a variable. The number of rows changes each week.

    I can start with Cells.find (What:="New SRs"... But I don't know how to select all the way to the blank row.

    Thanks for any help offered!

    Example:

    413 New SRs
    414 SR#
    415 54365-1
    416 54366-1
    417 54367-1
    418 54367-2
    ...
    717 54703-1
    718 Total Service: 303
    719 *Blank*
    720 Next Section

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: VBA select cell with a specific value and all cells below until blank

    If the section always start in row 413, and you want column A,

    Dim rng As Range
    ':
    Set rng = Worksheets("some_sheet").Range("A413")
    If Not IsEmpty(rng.Offset(1, 0).Value) Then Set rng = Range(rng, rng.End(xlDown))

  3. #3
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    Re: VBA select cell with a specific value and all cells below until blank

    Unfortunately the number of rows above changes every week as well. I believe I got a good answer already. I appreciate you, and will save your input in my bag of tricks!

    Have a great day.

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: VBA select cell with a specific value and all cells below until blank

    Quote Originally Posted by OmahaJay View Post
    Unfortunately the number of rows above changes every week as well.
    I am not sure how that affects the solution I posted but no problem, if hrlngrv's solution works for you then by all means use it.

  5. #5
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    Re: VBA select cell with a specific value and all cells below until blank

    Quote Originally Posted by Rick Rothstein View Post
    I am not sure how that affects the solution I posted but no problem, if hrlngrv's solution works for you then by all means use it.
    To clarify, your one line of code did work. The number of rows did not affect your code. I just need to tweak it to include columns A through S. Thanks again for your help.

  6. #6
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    Re: VBA select cell with a specific value and all cells below until blank

    Quote Originally Posted by hrlngrv View Post
    If the section always start in row 413, and you want column A,

    Dim rng As Range
    ':
    Set rng = Worksheets("some_sheet").Range("A413")
    If Not IsEmpty(rng.Offset(1, 0).Value) Then Set rng = Range(rng, rng.End(xlDown))
    Unfortunately the number of rows above changes every week as well, so the section does not always start at 413. I believe I got a good answer already. I appreciate you, and will save your input in my bag of tricks!

    Have a great day.

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: VBA select cell with a specific value and all cells below until blank

    Assuming you are searching column A and that cell A1 is a header (that is, it is not a section label), then this single line of code will find the cell and select its section...
    Range(Columns("A").Find("New SRs", [A1], xlValues, xlWhole, , xlNext, False, , False), Cells(Rows.Count, "A")).SpecialCells(xlConstants).Areas(1).Select
    Note: You should include an error trap if it would be possible for the searched for label not to be in the column.

  8. #8
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    Re: VBA select cell with a specific value and all cells below until blank

    This is 99% what I need. A copy/paste into my code worked perfectly! Thank you so much. I will fiddle with it so I can select columns A through S. Shouldn't be too hard.

    Thank you so much!

  9. #9
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    Re: VBA select cell with a specific value and all cells below until blank

    Quote Originally Posted by Rick Rothstein View Post
    Assuming you are searching column A and that cell A1 is a header (that is, it is not a section label), then this single line of code will find the cell and select its section...
    Range(Columns("A").Find("New SRs", [A1], xlValues, xlWhole, , xlNext, False, , False), Cells(Rows.Count, "A")).SpecialCells(xlConstants).Areas(1).Select
    Note: You should include an error trap if it would be possible for the searched for label not to be in the column.
    This was the code that worked. Apparently I'm "slightly" better at excel than I am at using this forum!

  10. #10
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: VBA select cell with a specific value and all cells below until blank

    Give this a try (I show my addition in red)...
    Range(Columns("A").Find("New SRs", [A1], xlValues, xlWhole, , xlNext, False, , False), Cells(Rows.Count, "A")).SpecialCells(xlConstants).Areas(1).Resize(,19).Select

  11. #11
    Registered User
    Join Date
    02-02-2021
    Location
    Nebraska
    MS-Off Ver
    Pro Plus 2016
    Posts
    7

    Re: VBA select cell with a specific value and all cells below until blank

    Quote Originally Posted by Rick Rothstein View Post
    Give this a try (I show my addition in red)...
    Range(Columns("A").Find("New SRs", [A1], xlValues, xlWhole, , xlNext, False, , False), Cells(Rows.Count, "A")).SpecialCells(xlConstants).Areas(1).Resize(,19).Select
    All hail Rick Rothstein! Thank you sir!

+ 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. [SOLVED] Fill blank cells,select from the last cell
    By salazarcl.17 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-05-2016, 01:18 PM
  2. Delete Cells with Specific Value and All Blank Cells Until Next Populated Cell is Checked
    By rdtrahan1906 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2014, 05:50 PM
  3. Replies: 10
    Last Post: 07-08-2013, 01:47 PM
  4. Replies: 2
    Last Post: 07-26-2012, 09:57 AM
  5. Select a specific column till it identifies blank cell and to format
    By k1234y in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2012, 12:35 AM
  6. Find specific value in a cell, select the cell and copy all cells beneath
    By Mothman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2010, 03:26 AM
  7. [SOLVED] Select all cells in a column up to a blank cell
    By nemadrias in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2006, 04:10 PM

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