PDA

View Full Version : Delete 2 cells.



5element
07-15-2017, 07:48 AM
Hello,
The below macro removes duplicates in column A and is working fine, butI want the macro to also remove information from column B because, the data from column A is assigned to column B

Not sure how to do this?
Could you help me.





Set Des = ActiveWorkbook.Worksheets("Des")
Set Copy1 = ActiveWorkbook.Worksheets("Copy1")
Sheet1.Range("A1:A200").Copy Destination:=Des.Range("A1")
Sheet1.Range("B1:B200").Copy Destination:=Des.Range("B1")
Copy1.Range("E1:E200").Copy Destination:=Des.Range("C1")


' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False


' Get count of records to search through (list that will be deleted).
iListCount = Sheets("Des").Range("A1:A10").Rows.Count


' Loop through the "master" list.
For Each x In Sheets("Des").Range("C1:C200")
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Des").Cells(iCtr, 3).Value Then
' If match is true then delete row.
Sheets("Des").Cells(iCtr, 1).Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
Next iCtr


Next


Application.ScreenUpdating = True

Paul_Hossler
07-15-2017, 06:57 PM
Taking a guess ....



Sheets("Des").Cells(iCtr, 1).Resize(1,2).Delete xlShiftUp

jolivanes
07-15-2017, 09:50 PM
Why the 200. Is that so you'll have it all? Just a number that is well past the last used row?
If the three ranges are copied from the same sheet (Copy1 I think) you can replace this

Sheet1.Range("A1:A200").Copy Destination:=Des.Range("A1")
Sheet1.Range("B1:B200").Copy Destination:=Des.Range("B1")
Copy1.Range("E1:E200").Copy Destination:=Des.Range("C1")
with this

Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
With Sheets("Copy1")
.Range("A1:A" & lr & ",B1:B" & lr & ",E1:E" & lr).Copy Sheets("Des").Range("A1")
End With

p45cal
07-16-2017, 04:07 AM
Why the 200. Is that so you'll have it all? Just a number that is well past the last used row?
One possible reason might be to overwrite any pre-existing data on the destination sheet; if the list copied over the previous time was longer than this time, you might leave old data if you copy over less than the fixed 200 rows.

5element
07-16-2017, 08:39 AM
Taking a guess ....



Sheets("Des").Cells(iCtr, 1).Resize(1,2).Delete xlShiftUp


Thank you. It's work.

5element
07-16-2017, 08:41 AM
Sheet1 and Copy1 it is different sheet. But I have a lot of row, 200 is example. I must copied more less 2000 row.