Consulting

Results 1 to 4 of 4

Thread: Solved: Finding the last empty column in a row?

  1. #1

    Solved: Finding the last empty column in a row?

    Hi
    How can I find the last empty column in a row. I need to find the last row and also the last column in that row so I can paste data all in one row. In the code below, it works for finding the last row, but the column part doesn't work. It gives an error. I tried using End(xlleft) and .End(xlRight) but those give an error that says "400". .End(xlup) and .End(xldown) work fine.

    Appreciate any help!

    [VBA]
    endrow_d = basebook.Sheets("raw data").Cells(65536, 1).End(xlUp).Row + 1

    endcol_d = basebook.Sheets("raw data").Cells(endrow_d, 100).End(xlLeft)
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    endcol_d = basebook.Sheets("raw data").Cells(endrow_d, Columns.Count).End(xlToLeft).Column
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    XLD's finds the last with data. Just add 1 or use Offset.
    [VBA]endcol_d = basebook.Sheets("raw data").Cells(endrow_d, Columns.Count).End(xlToLeft).Column+1[/VBA]

  4. #4
    Great!! Thanks! That worked perfect!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •