+ Reply to Thread
Results 1 to 4 of 4

Unknown column and last row count

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Unknown column and last row count

    Hello again you beautiful people,

    Another issue that is driving me insane.

    Ok, I have a imported spreadsheet where the columns change on a regular basis so I have to add a helper column as an additional column the end which autofils team members down to the last row.

    I know how to find the last column to add this helper column and I know how to count the last row in a predefined column and that the autofill function works fine (for example I am counting column A below)

    Dim lastRow As Long
    Set sht = ThisWorkbook.Worksheets("Sheet1")
    lastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
    Now this is where my problem is, as my data will not always be in column A, one day it could be in B and another Z! So I can't program the macro as I don't know the last column of data each day to rows.count.

    I am not sure if it can be done but is there a way to do something like below:

    lastRow = sht.Cells(sht.Rows.Count, "last_column").End(xlUp).Row[/CODE]

    As always, any help will be greatly appreciated.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Unknown column and last row count

    Try:
    Dim lastRow As Long, lCol As Long
    Set sht = ThisWorkbook.Worksheets("Sheet1")
    With sht
        lCol = .UsedRange.Columns.Count
        lastRow = .Cells(.Rows.Count, lCol).End(xlUp).Row
    End With
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Re: Unknown column and last row count

    Works perfickly,

    Many thanks Mumps1

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Unknown column and last row count

    You are very 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. [SOLVED] Sum/Count between unknown number of Values
    By benrhopkins in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-27-2019, 01:51 PM
  2. Looking for a way for excel to count unknown repeating values?
    By Kblue74 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  3. Looking for a way for excel to count unknown repeating values?
    By Bernie Deitrick in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 07:05 AM
  4. [SOLVED] Looking for a way for excel to count unknown repeating values?
    By Kblue74 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  5. Looking for a way for excel to count unknown repeating values?
    By Kblue74 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  6. Looking for a way for excel to count unknown repeating values?
    By Kblue74 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  7. [SOLVED] conducting a count on unknown number of records
    By Giz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2005, 04:06 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