Comparing cell values and moving whole rows

comppi

New Member
Joined
Jul 2, 2014
Messages
7
I'm trying to compare the values of columns B and G and if any of the cells are G < B, I would like to move the whole row into the second worksheet. And only if possible, it would be awesome if the macro could check column A for duplicates before the value comparison and sum up the column B if there are duplicates. In my example row 6 and 7 on column A have the same suppliers code and the amount totals to 2.
In this case for example, the value of the third row of G is lower than B, and therefore I would like the whole row 3 to be cut out from worksheet 1 and moved to worksheet 2.

I've tried making my own macros from other examples, but haven't really found anything that would suite my needs and fulfill the objective. I would be so thankful for any help provided! I understand that this might seem really complicated since I'm not that good at phrasing my problem :(.

Original view of sheet 1:
SUPPLIERSCODEORDERAMOUNTPRODUCTNAMEBARCODESUPPLIERSCODEWAREHOUSE STOCK
12342,00TEST PRODUCT 1999999912342,00
12354,00TEST PRODUCT 2999999912353,00
12361,00TEST PRODUCT 3999999912361,00
12371,00TEST PRODUCT 4999999912371,00
12381,00TEST PRODUCT 5999999912381,00
12381,00TEST PRODUCT 59999999

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

The macro would first make the sheet look like:
SUPPLIERSCODEORDERAMOUNTPRODUCTNAMEBARCODESUPPLIERSCODEWAREHOUSE STOCK
12342,00TEST PRODUCT 1999999912342,00
12354,00TEST PRODUCT 2999999912353,00
12361,00TEST PRODUCT 3999999912361,00
12371,00TEST PRODUCT 4999999912371,00
12382,00TEST PRODUCT 5999999912381,00

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

And then cut out the rows in which G<B, so the sheet 1 would look like:
SUPPLIERSCODEORDERAMOUNTPRODUCTNAMEBARCODESUPPLIERSCODEWAREHOUSE STOCK
12342,00TEST PRODUCT 1999999912342,00
12361,00TEST PRODUCT 3999999912361,00
12371,00TEST PRODUCT 4999999912371,00

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

And Sheet 2:
12354,00TEST PRODUCT 2999999912353,00
12382,00TEST PRODUCT 5999999912381,00

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Last edited:
Yes, that is correct. If the warehouse stock is lower than the order quantity, then move the whole row to the second sheet. You are perhaps the most helpful person I've ever met on any forum. Cheers!
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi

Put this under your button 2

Kev

Code:
Application.ScreenUpdating = False

Static fx, Lr, LrRange, WS1, WS2, RowHolder
Set WS1 = Sheets("sheet1") ' Alter Sheetname if Required
Set WS2 = Sheets("sheet2") ' Alter Sheetname if Required
WS1.Activate
Lr = ActiveSheet.Range("a70000").End(xlUp).Row
      
LrRange = ActiveSheet.Range("a2:a" & Lr).Address(False, False)

For Each fx In ActiveSheet.Range(LrRange)
        If fx.Value > "" Then
        
        RowHolder = fx.Address(0, 0)
        
        
           If fx.Offset(0, 1).Value = fx.Offset(0, 6).Value Then
            
                    'Do Nothing
            ElseIf fx.Offset(0, 1).Value > fx.Offset(0, 6).Value Then
            
                   fx.EntireRow.Cut
                   
                    
                    WS2.Activate
                    
                             If ActiveSheet.Range("a2").Value = "" Then
                             
                                ActiveSheet.Range("a2").Select
                                ActiveSheet.Paste
                                WS1.Activate
                                Range(RowHolder).Select
                                ActiveCell.EntireRow.Select
                                Selection.Delete Shift:=xlUp
                                GoTo ender
                                
                                
                             ElseIf ActiveSheet.Range("a2").Value > "" And ActiveSheet.Range("a3").Value = "" Then
                             
                                ActiveSheet.Range("a3").Select
                                ActiveSheet.Paste
                                WS1.Activate
                                Range(RowHolder).Select
                                ActiveCell.EntireRow.Select
                                Selection.Delete Shift:=xlUp
                                GoTo ender
                                                          
                                                          
                             ElseIf ActiveSheet.Range("a2").Value > "" And ActiveSheet.Range("a3").Value > "" Then
                             
                                ActiveSheet.Range("a2").Select
                                Selection.End(xlDown).Select
                                ActiveCell.Offset(1, 0).Select
                                ActiveSheet.Paste
                                WS1.Activate
                                Range(RowHolder).Select
                                ActiveCell.EntireRow.Select
                                Selection.Delete Shift:=xlUp
                                GoTo ender
                             End If
             End If
        End If
ender:
WS1.Activate

Next fx
 
Upvote 0

Forum statistics

Threads
1,215,988
Messages
6,128,145
Members
449,426
Latest member
revK

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