+ Reply to Thread
Results 1 to 6 of 6

identify last row containing text in column B and use row number in cell range

  1. #1
    Registered User
    Join Date
    05-09-2017
    Location
    London
    MS-Off Ver
    2013
    Posts
    9

    identify last row containing text in column B and use row number in cell range

    Hello Excel Forum gurus,

    I was wondering if you'd be able to help me with a VBA script that I'm trying to create.

    I want to identify what the last row containing any text in column B is, then use this row within a cell range to automatically apply a formula to row H.

    The bit I'm having trouble with is "Range("H2:HLastRow").Select". Naturally, I know this command won't work but it displays what I'm trying to achieve.

    My VBA is as follows:


    Sub LastRowInOneColumn()

    'Find the last used row in a Column: column B in this example
    Dim LastRow As Long
    With ActiveSheet
    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    End With
    'Select the cell range of H2 to H with the last row of column B
    Range("H2:HLastRow").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown

    End Sub

    Many thanks in advance for your help,

    Matt

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: identify last row containing text in column B and use row number in cell range

    Please use CODE tags when posting code.

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    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
    48,127

    Re: identify last row containing text in column B and use row number in cell range

    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.

    Click on Edit to open your thread, then 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

    This
    Please Login or Register  to view this content.
    should be this
    Please Login or Register  to view this content.
    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


  4. #4
    Registered User
    Join Date
    05-09-2017
    Location
    London
    MS-Off Ver
    2013
    Posts
    9

    Re: identify last row containing text in column B and use row number in cell range

    Thanks guys, that's spot on!

    Apologies for not inserting the code correctly. I'll make sure that it's displayed correctly next time.

    Many thanks,

    Matt

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: identify last row containing text in column B and use row number in cell range

    Happy to help. If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. You can also "add reputation" to those who helped you. Thanks.

  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
    48,127

    Re: identify last row containing text in column B and use row number in cell range

    You're welcome.

+ 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. VBA code to identify the cell number in a column which contains a specific text
    By rshnkmr39 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2014, 03:38 AM
  2. Formula to identify part of a text in cell from range of cells & insert adjacent cell text
    By Novicebutnotforlong in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-19-2013, 02:11 AM
  3. How to find a cell from a range and identify its column number
    By JamesGoulding85 in forum Excel General
    Replies: 2
    Last Post: 06-06-2013, 08:29 AM
  4. [SOLVED] Macro assistance to identify dates in one range and place text in a cell in worksheets
    By lilsnoop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2013, 12:29 PM
  5. Replies: 1
    Last Post: 02-08-2013, 12:24 PM
  6. Replies: 1
    Last Post: 05-09-2012, 01:30 PM
  7. Identify the column of a range by letter instead of number
    By Peter Rooney in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-10-2006, 06:35 AM

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