Automatically Move Row to Another Sheet Based On Cell Value

marleymstuhmcke

New Member
Joined
Nov 30, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Complete VBA newbie here, so any help would be much appreciated!

I am trying to AUTOMATICALLY copy/duplicate a row of data from sheet “Current” to another sheet “Exceeded”.

I have a table of data that I am manually inputting data into every day, to keep on track of all staff’s uniforms. The active sheets are A-L, with unlimited rows (as I will be added to the list every day). The first row of actual data starts at A3.
  • Columns G, I & L – I have added a “function” to reflect on the value in the cells next to it. (G3 = 5 – F3). So, each staff member gets a limit of 5 shirts. I put in a calculation so that cells G, I & L reflect on how many they have remaining. Once this limit is exceeded, the cell will go to 0 and is conditionally formatted to turn red (all cells containing 0 value).
I am trying to get a VBA to AUTOMATICALLY duplicate/copy the rows with 0 value into the next tab “Exceed”. So, if G3 is 0 in tab “Current”, the entire row (A-L) will get duplicated/copied into the next tab “Exceed”.

I have attached a photo of my worksheet for reference. If you have any questions, please let me know. I have never used this type of coding before, so I am fish out of water!!

1701385840692.png
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Maybe something like

VBA Code:
Sub Filterit()
    Application.ScreenUpdating = False
    
    With Sheets("Current").Range("G2:G" & Sheets("Current").Range("G" & Rows.Count).End(xlUp).Row)
    
        .AutoFilter 1, 0
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
        
    End With
       
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Maybe something like

VBA Code:
Sub Filterit()
    Application.ScreenUpdating = False
   
    With Sheets("Current").Range("G2:G" & Sheets("Current").Range("G" & Rows.Count).End(xlUp).Row)
   
        .AutoFilter 1, 0
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
       
    End With
      
    Application.ScreenUpdating = True
End Sub
Yes! That has worked, but unfortunately it is only picking up the 0 in G column, not I and J aswell.
Thankyou! If I input more data will this also transfer over?
 
Upvote 0
Try the code below on a copy of your workbook..
VBA Code:
Sub Filterit2()
    Application.ScreenUpdating = False
 
    With Sheets("Current").Range("A2:L" & Sheets("Current").Range("A" & Rows.Count).End(xlUp).Row)
 
        .AutoFilter 7, 0
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
     
        .AutoFilter 9, 0
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
     
        .AutoFilter 10, 0
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
   
    End With

    With Sheets("Exceeded").Range("A2:L" & Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Row)
        .Sort Key1:=.Cells(1), Header:=xlNo
        .Columns(1).RemoveDuplicates Columns:=1, Header:=xlNo
        On Error Resume Next
        .Columns(1).SpecialCells(4).EntireRow.Delete
        On Error GoTo 0
    End With
    
    Application.ScreenUpdating = True
End Sub

If I input more data will this also transfer over?
No, you'll have to clear all the data on sheet Exceeded and rerun the code
 
Last edited:
Upvote 0
Do you need to use VBA? Or could you use a simple formula? Because with Excel 365 (which you have according to your profile) it is very simple:
Convert your data to a table ("Tabla1" in my case) an apply this formula in B14 (or wherever you want your result table):

Libro1
BCDEFGHIJKL
3DateNameDepartmentWhere PurchasedHi Visibility ShirtQuantity RemainingLong TrousersQuantity Remaining25 in 1 Jacket Soft ShellQuantity Remaining3
403/07/2023Name01DepotThe Uniform Zone5050110
503/07/2023Name02DepotThe Uniform Zone5511
604/07/2023Name03DepotThe Uniform Zone50232
704/07/2023Name03DepotThe Uniform Zone50502
805/07/2023Name04DepotThe Uniform Zone5232
915/07/2023Name05DepotThe Uniform Zone5501
10
11
12
13
14DateNameDepartmentWhere PurchasedHi Visibility ShirtQuantity RemainingLong TrousersQuantity Remaining25 in 1 Jacket Soft ShellQuantity Remaining3
1503/07/2023Name01DepotThe Uniform Zone5050110
1604/07/2023Name03DepotThe Uniform Zone5023002
1704/07/2023Name03DepotThe Uniform Zone5050002
1815/07/2023Name05DepotThe Uniform Zone0550001
Hoja1
Cell Formulas
RangeFormula
B14:L18B14=VSTACK(Tabla1[#Headers], FILTER(Tabla1,Tabla1[Quantity Remaining]*Tabla1[Quantity Remaining2]*Tabla1[Quantity Remaining3]=0))
Dynamic array formulas.
 
Upvote 0
You are right, he doesn't need to. It was more of a suggestion. It's easier, in mho, to work with data, use formulae and maintain you worksheet this way.
But here it is without table:

Libro1
CDEFGHIJKLM
3DateNameDepartmentWhere PurchasedHi Visibility ShirtQuantity RemainingLong TrousersQuantity Remaining25 in 1 Jacket Soft ShellQuantity Remaining3
403/07/2023Name01DepotThe Uniform Zone5050110
503/07/2023Name02DepotThe Uniform Zone5511
604/07/2023Name03DepotThe Uniform Zone50232
704/07/2023Name03DepotThe Uniform Zone50502
805/07/2023Name04DepotThe Uniform Zone5232
915/07/2023Name05DepotThe Uniform Zone5501
10
11
12
13
14DateNameDepartmentWhere PurchasedHi Visibility ShirtQuantity RemainingLong TrousersQuantity Remaining25 in 1 Jacket Soft ShellQuantity Remaining3
1503/07/2023Name01DepotThe Uniform Zone5050110
1604/07/2023Name03DepotThe Uniform Zone5023002
1704/07/2023Name03DepotThe Uniform Zone5050002
1815/07/2023Name05DepotThe Uniform Zone0550001
Hoja1
Cell Formulas
RangeFormula
C14:M18C14=VSTACK(Hoja1!$C$3:$M$3, FILTER(Hoja1!$C$4:$M$9,Hoja1!$H$4:$H$9*Hoja1!$J$4:$J$9*Hoja1!$M$4:$M$9=0))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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