Add Delete function to my Copy Code

Arek

New Member
Joined
Aug 15, 2011
Messages
13
Good Afternoon,

I have the code below working well for the exception of deleting the row out of which my data was copied. Also if Column A is blank on sheet "Allan" it does not find the row(I need it to copy if row 2 is not blank.

Any help would be appreciated.

Public Sub CopyRows()
Sheets("Allan").Select
' Find the last row of data
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
' Loop through each row
For x = 2 To FinalRow
' Decide if to copy based on column H
ThisValue = Cells(x, 3).Value
If ThisValue = "D" Then
Cells(x, 1).Resize(1, 33).Copy
Sheets("Finished Projects").Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Allan").Select
End If
Next x
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I have not completely understood your requirsement

for what I guess:

Code:
"Cells(x, 1).Resize(1, 33).Copy"

instead of copy you want to "cut: is it so?

if you cut the data 1row 33 column then those cells will be blank.
If our total number of columns is only 33 then you can cut the entire row somethinglike this

Code:
cells(x,1).entirerow.cut

but there is one plroblem as you are cutting(or deleting rows there will be some problem inb looping that is in x value

so in the loop you modify this
Code:
For x = 2 To FinalRow
as follow
Code:
For x = FinalRow to 2 step -1

as you learn vba more and more you need not select the sheets. without selecting the sheets or ranges you can use "with" funcion.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top