I wish to Transfer a row from one Excel Sheet to another using two criteria

RMadden

New Member
Joined
May 30, 2022
Messages
15
Office Version
  1. 2021
Platform
  1. Windows
I have an excel spreadsheet (Excel 2016) with a number of sheets (Local Suburbs). Sheet1 (called "DataInput") collects data from outside the sheet and laying it in a row (basically I copy from another source and drop it there). Now column B has a heading "Unique Number" at B1 with the data starting in Row 2 - This number is as headed different for each row of data.
Also there is a column headed up "Hub location". This is column "H".
My problem is I wish to add any row of data that is added into the "DataInput" sheet across to sheet2 (Kariong) based on the following criteria: -
* Add to the next row after that one that has data in it;
* Only do so if that row of data is not already there; and
* Only transfer rows that relate to the suburb "Kariong" as shown in column H.

I have been able to get the first two done via Command Button with the following code but not to sort out any rows that doesn't relate to "Kariong". I will replicate this button for other suburbs on their individual sheets unless there is an easier way (total suburbs would be ten). I thought if I could get one right the reat can be adapted easy enough.

VBA Code:
Private Sub CommandButton3_Click()

    Dim ws2 As Worksheet, ws1 As Worksheet
    Dim cell As Range, Found As Range
    Dim FirstFound As String
    Dim bCopyInv   As Boolean
    Dim counter    As Long
   
    Set ws2 = Sheets("Kariong")
    Set ws1 = Sheets("DataInput")
   
    For Each cell In ws1.Range("b1", ws1.Range("b" & Rows.Count).End(xlUp))
        bCopyInv = True
        Set Found = ws2.Columns("b").Find(What:=cell.Value, _
                                          LookIn:=xlValues, _
                                          LookAt:=xlWhole, _
                                          SearchOrder:=xlByRows, _
                                          SearchDirection:=xlNext, _
                                          MatchCase:=False)
        If Not Found Is Nothing Then
            FirstFound = Found.Address
            Do
                If Found.Offset(0, 2).Value = cell.Offset(0, 2).Value Then
                    bCopyInv = False
                    Exit Do
                End If
                Set Found = ws2.Columns("b").FindNext(after:=Found)
            Loop Until Found.Address = FirstFound
        End If
       
        If bCopyInv Then
            cell.EntireRow.Copy Destination:=ws2.Range("A" & Rows.Count).End(xlUp).Offset(1)
            counter = counter + 1
        End If
       
    Next cell
   
    MsgBox counter & " orders copied.", vbInformation, "Orders Copy Complete"
End Sub

I must admit I adapted this code from another example and whilst it works I am not sure about the "found.offset" portion as the original code had different criteria it was searching for
Any help you can give will be most appreciated. Thanking you in advance
 
Last edited by a moderator:
Hi, there I broke the code. I have inserted a column to the left of the featured column "H" and added two worksheets to the right on the end named PickingList and BackOrder. I now get a Runtime error 13 Type mismatch with the highlight on the line - ky=sh.name & etc - I not sure I should be writing code here or not.
I did try replacing the "H" with the new column "I" but didn't seem to help
The new column is a text field called "Approval Status" and I used the data in the first worksheet "DataInput" to create orders from the warehouse. These two sheets have no connection to the "suburb" sheets as such.
Is there an easy fix for this issue?
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You can put how the sheets are now.
Do you have formulas in column H or column I where the result has some kind of error like #N/A, #VALUE, etc?
 
Upvote 0
Here is a mini sheet for your perusal. your code runs behind the click button "Step 2". Originally Column "H" was the "Hub Location" which dictates which sheet each row was to go to. Alas the boss wanted the "Approval Status" column inserted pushing all collumns to the right.

StockOrderControl.xlsm
ABCDEFGHIJKLMNOPQRSTUVW
1Submission DateApproval StatusUnique NumberDateFirst NameLast NameEmailMob No:Hub LocationTo Be Auto FilledBrushcutter - FS560FS561 >> Mulching Blade[4000 713 3902] >> Standard Holding QtyBrushcutter - FS560FS561 >> Mulching Blade[4000 713 3902] >> On handBrushcutter - FS560FS561 >> Mulching Blade[4000 713 3902] >> Order PlacedBrushcutter - FS560FS561 >> Mulching Blade[4000 713 3902] >> Office Use OnlyBrushcutter - FS560FS561 >> Tri Blade[4000 713 4100] >> Standard Holding QtyBrushcutter - FS560FS561 >> Tri Blade[4000 713 4100] >> On handBrushcutter - FS560FS561 >> Tri Blade[4000 713 4100] >> Order PlacedBrushcutter - FS560FS561 >> Tri Blade[4000 713 4100] >> Office Use OnlyBrushcutter - FS560FS561 >> Saw Blade 225mm FS560/FS460/FS561[4000 713 4211] >> Standard Holding QtyBrushcutter - FS560FS561 >> Saw Blade 225mm FS560/FS460/FS561[4000 713 4211] >> On handBrushcutter - FS560FS561 >> Saw Blade 225mm FS560/FS460/FS561[4000 713 4211] >> Order PlacedBrushcutter - FS560FS561 >> Saw Blade 225mm FS560/FS460/FS561[4000 713 4211] >> Office Use OnlyBrushcutter - FS560FS561 >> Duro Cut Line - FS460/FS560/FS561[0000 930 3503] >> Standard Holding Qty
22022/06/07 14:14:29COMPLETEDHUBREQ000000001Jun 5, 2022BradJacksonrobert@juparo.com.au0417291641Kariong1102203304
32022/06/09 13:59:13In ProgressHUBREQ000000005Jun 9, 2022RobertTestmanrobert.madden@rfs.nsw.gov.au0400708328Singleton404002020044020
42022/06/10 08:11:14In ProgressHUBREQ000000006Jun 10, 2022RobertTestrobert.madden@rfs.nsw.gov.au0400708328Wyong40301020101042220
52022/06/10 09:56:00In ProgressHUBREQ000000007Jun 10, 2022TestyMandaterobert.madden@RFS.nsw.gov.au0417291641Taree201010108221110
62022/06/10 10:17:02In ProgressHUBREQ000000008Jun 10, 2022RobertDunloprobert.madden@rfs.nsw.gov.au0417291641Wauchope202001010022010
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
DataInput
 

Attachments

  • WindowView.JPG
    WindowView.JPG
    143.7 KB · Views: 14
Upvote 0
You can put how the sheets are now.
Do you have formulas in column H or column I where the result has some kind of error like #N/A, #VALUE, etc?
Hi there, have you had chance to review the new info that I posted on the 19th?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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