VBA macro to automatically copy whole row to another sheet based on cell value

Heracek

New Member
Joined
May 5, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hello, I would like to ask for a help creating a VBA macro that will automatically copy the whole row when value is entered into a certain cell.

I am on Windows 10, Excel 365 version.

Here is what I am working with, when a date (the script could check for any value but a date will be entered here) is entered in column C and cell C3 onward in sheet 2 (2022) I need the row to be copied over to sheet 1 (Pece):

1651748203412.png


I tried to copy and edit various macros I found online but I failed to make any of them work.

Thanks in advance!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the Board!

Right-click on the sheet name tab at the bottom of your "2022" sheet, select "View Code", and paste this VBA code to the VB Editow window that pops up:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit sub if multiple cells updated at once
    If Target.CountLarge > 1 Then Exit Sub

'   Check to see if column C after row 2 updated
    If Target.Column = 3 And Target.Row > 2 Then
'       See if a date is entered in column C
        If IsDate(Target) And Target > 0 Then
'           Copy row to bottom of Pece sheet
            Rows(Target.Row).Copy Sheets("Pece").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    End If

End Sub
This will automatically copy the row to the "Pece" sheet when a valid date is manually entered into column C of the "2022" sheet.
 
Upvote 0
Solution
So, does that work for you?
 
Upvote 0
Thanks! It does work in the most basic way that I requested and if you don't mind I will have some questions or request for adjustments later, when I can get back to it.
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,258
Members
449,149
Latest member
mwdbActuary

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