简体   繁体   中英

VBA Stuck after certain loop

I am trying to write a code in excel VBA but am stuck at one point where i need help from you experts please. File is attached

The scenario is this that i have a data where column D has shipment # and when i receive it i put yes in column E. I need to prepare a report where in column E there is blank then if there is blank in column E then copy the shipment number of that blank from column D and paste it in column J which i have already done coding. but now i am stuck as I need to copy the name also which is in column B with same criteria. meaning that for the same shipment number which is copied in column J the name from column B should be copied and pasted in column K by finding the shipment number in column D and then selecting the name from column B for that shipment number.

Image is the data I have

图像是我拥有的数据

Code:

代码

Hi Please find the below code , This is working fine at my end.

Sub so()
lRow = ThisWorkbook.ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
lRow1 = ThisWorkbook.ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
ThisWorkbook.ActiveSheet.Range("E1").AutoFilter Field:=2, Criteria1:=""
ThisWorkbook.ActiveSheet.Range("D1:D" & lRow).SpecialCells(xlCellTypeVisible).Copy       Range("J1")
ThisWorkbook.ActiveSheet.Range("B1:B" & lRow1).SpecialCells(xlCellTypeVisible).Copy Range("K1")
Selection.AutoFilter
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM