Consulting

Results 1 to 9 of 9

Thread: VBA CODE - SEARCH AND COPY

  1. #1
    VBAX Newbie
    Joined
    Jul 2013
    Posts
    2
    Location

    Question VBA CODE - SEARCH AND COPY

    Hi - I'm new and need help.
    I'm looking for vba macro that will go to a column (say column B),
    look for the last cell with data in that column,
    then search the column for cell's with no data in it and,
    copy the data in the cell above the empty cell into the empty cell?

    I hope this makes sens and some can help me.

    Thanks
    Neels Borstlap

  2. #2
    VBAX Regular
    Joined
    Nov 2011
    Posts
    33
    Location
    Plz try this[Code]Sub copy_last()With ActiveSheet mylastcol = _ .Cells.Find("*", after:=.Cells(1), _ LookIn:=xlFormulas, lookat:=xlWhole, _ searchdirection:=xlPrevious, _ searchorder:=xlByColumns).Column .Cells(1, mylastcol + 1) = .Cells(Rows.Count, "B").End(xlUp).Value End With End Sub[Code]

  3. #3
    VBAX Newbie
    Joined
    Jul 2013
    Posts
    2
    Location
    Hi Lotuxel

    Thanks for the help.
    Sorry but I'm new to this stuff.
    If I paste you code in a module is give me all kinds of errors.
    Can you help again.
    I think it is because the code is in one line and I do not now how to split it.

    Thanks
    Neels

  4. #4
    VBAX Regular
    Joined
    Nov 2011
    Posts
    33
    Location
    Quote Originally Posted by lotuxel
    Plz try this[code]Sub copy_last()With ActiveSheet mylastcol = _ .Cells.Find("*", after:=.Cells(1), _ LookIn:=xlFormulas, lookat:=xlWhole, _ searchdirection:=xlPrevious, _ searchorder:=xlByColumns).Column .Cells(1, mylastcol + 1) = .Cells(Rows.Count, "B&quot.End(xlUp).Value End With End Sub[code]

  5. #5
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    The forum seems to be acting strangely and not parsing Tags. This is a cross post from http://www.mrexcel.com/forum/excel-q...pty-cells.html however and you should identify it as such.
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    As I posted at MrExcel since this forum is not formatting text in tags properly.

  7. #7
    VBAX Regular
    Joined
    Nov 2011
    Posts
    33
    Location
    I'm sorry, why my Reply post's toolbar can not use "VBA" ([code][code]) icon ?

  8. #8
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Because the forum software was upgraded. You should now just use Code tags.
    MsgBox "test"

  9. #9
    VBAX Regular
    Joined
    Nov 2011
    Posts
    33
    Location
    Dear Kenneth,
    Thanks for the advised.
    Let try now.

    Hi Neelsbor,

    Sub copy_last() With ActiveSheet mylastcol = .Cells.Find("*", after:=.Cells(1), _ LookIn:=xlFormulas, lookat:=xlWhole, _ searchdirection:=xlPrevious, _ searchorder:=xlByColumns).Column .Cells(1, mylastcol + 1) = .Cells(Rows.Count, "B").End(xlUp).Value End With End Sub
    Last edited by Simon Lloyd; 07-24-2013 at 12:06 AM. Reason: added code tags

Posting Permissions

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