PDA

View Full Version : [SOLVED:] Select data down to next empty cell in column



oam
05-14-2018, 05:16 PM
I am using the VBA FIND feature in Excel 2010 (see code below) to locate and select employee numbers from a report generated by another system. After the employee number is selected, need to select down to the next empty cell within the column and everything in between. The information for each employee is different each day, each employee could have 2 lines of information or 15 lines so the code would select the employee number and select down to the first empty cell after the employee number.

Hope this makes sense and thank you any and all help


GCell.Select
If GCell Is Nothing Or GCell = "" Then GoTo Line1
IsEmpty Range(GCell.End(xlDown).offset(1, 0), GCell.offset(0, 20)).Select
lr = lastrow(DestSh)
Selection.Copy Destination:=Sheets("ProductionTotals").Range("C" & lr + 3)
Line1:
GCell1.Select
If GCell1 Is Nothing Or GCell1 = "" Then GoTo Line2
IsEmpty Range(GCell1.End(xlDown).offset(1, 0), GCell1.offset(0, 20)).Select
lr = lastrow(DestSh)
Selection.Copy Destination:=Sheets("ProductionTotals ").Range("C" & lr + 3)
Line2:
GCell2.Select
If GCell2 Is Nothing Or GCell2 = "" Then GoTo Line3
IsEmpty Range(GCell2.End(xlDown).offset(1, 0), GCell2.offset(0, 20)).Select
lr = lastrow(DestSh)
Selection.Copy Destination:=Sheets("ProductionTotals ").Range("C" & lr + 3)

oam
05-14-2018, 05:40 PM
I figured it out. Sorry for asking a question with out thinking it through.

jolivanes
05-14-2018, 09:18 PM
You only show part of the code but would this not do the same?


Sub Maybe()
Range(Selection, Selection.End(xlDown)).Copy Sheets("ProductionTotals ").Range("C" & lr + 3)
End Sub

If not, could you be so kind and show your fixed code for people that are searching for a solution to the same or similar problem.

oam
05-14-2018, 10:05 PM
Sorry for any inconvenience for this post!

jolivanes (http://www.vbaexpress.com/forum/member.php?1993-jolivanes),

You are correct the code I posted will and does work for the problem I posted the only problem I had was there was an extra row in between the selection and the next row empty row. In my hast and frustration, I over looked the extra space. When I removed the space the code I submitted worked. Again I apologizes for any inconvenience this my have caused.

jolivanes
05-14-2018, 11:00 PM
Thank you for updating.