VBA Cut a row based off of the data in a cell and paste it into a table on another sheet.

PaulOPTC

New Member
Joined
Jan 13, 2022
Messages
48
Office Version
  1. 365
Platform
  1. Windows
Hey!

Hoping for some help once again.

I have a table that tracks my rentals:

Job Number:Job Name:Equipment rented: Employee:Company Rented from:Rental Start Date:Length of rentalEstimated Due Date:Date Returned:Returned By:Total cost of the rental:Rental Complete
Scissor lift3/25/20221Week(s)4/1/2022

I would like it so that when a button is pushed, any rows that have the rental marked as "Returned" in the last Column (Column M)

would be completely cut from that table

and Pasted onto another table on a different sheet. (The paste has to go into the table, so maybe "Insert copied cells"? )

It has to be removed from the first table completely, we can delete the entire row if that's easier.

I am really not sure why I am having such a hard time with this one.


Sheet with the first able on it: "Rental Tracker"
Second sheet we want to cut it into "Rental MTLink"

Here is some code I have tried:

VBA Code:
Sub returnstep1()


Dim c As Range
Dim Source As Worksheet
Dim Target As Worksheet


Set Source = ActiveWorkbook.Worksheets("Rental Tracker")
Set Target = ActiveWorkbook.Worksheets("Rental MTLink")


For Each c In Source.Range("M3:M" & Source.Cells(Rows.Count, 1).End(xlUp).Row)
   If c = "Returned" Then
      c.EntireRow.Copy
      Target.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
   End If
Next c
End Sub

That is close, but it does not paste it into the table on the other sheet, it pastes it right below it.



This one doesn't work at all.




Code:
Sub ReturnStep1Broken()
'
' ReturnButton Macro

Sheets("Rental Tracker").Select

Sheets("Rental MTLink").Visible = True
Sheets("Rental Tracker").Select

   Set Rng = Range("M3" & Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row)
    For i = Rng.Cells.Count To 1 Step -1
        If Rng(i).Value = "Returned" Then Range(Rng(i).EntireRow).Copy

Sheets("Rental MTLink").Select
      Rows("3:3").Select
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
   

        Sheets("Rental Tracker").Select
        If Rng(i).Value = "Returned" Then Range(Rng(i).EntireRow).Delete

    Next i
 

End Sub



I clearly still dont know how to write code in VBA, so any help you can offer is appreciated!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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