PDA

View Full Version : VBA CODE - SEARCH AND COPY



NeelsBor
07-22-2013, 08:10 PM
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

lotuxel
07-22-2013, 09:14 PM
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]

NeelsBor
07-22-2013, 09:51 PM
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

lotuxel
07-23-2013, 01:36 AM
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]

Teeroy
07-23-2013, 04:25 AM
The forum seems to be acting strangely and not parsing Tags. This is a cross post from http://www.mrexcel.com/forum/excel-questions/715472-visual-basic-applications-code-search-column-copy-paste-empty-cells.html however and you should identify it as such.

Kenneth Hobs
07-23-2013, 06:32 AM
As I posted at MrExcel since this forum is not formatting text in tags properly.

lotuxel
07-23-2013, 07:30 PM
I'm sorry, why my Reply post's toolbar can not use "VBA" ([code][code]) icon ?

Kenneth Hobs
07-23-2013, 08:28 PM
Because the forum software was upgraded. You should now just use Code tags.

MsgBox "test"

lotuxel
07-23-2013, 09:49 PM
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