Don't want to Copy Data Twice

nabeelahmed

Board Regular
Joined
Jun 19, 2020
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hi everyone, I am copying data from one sheet to other using PRNo criteria, whenever i enter PRNo. in cell "from" and "To" and how many time i press my Macro Button it is being copy every time to the next row, i don't want same PRno. data to be copied more than one time. It should be copy once and for the next entry when i will use another PRno. then next data should be copy in the next rows and so on..... my coding is below .

Private Sub CommandButton1_Click()

Dim fromPRNo As String: fromPRNo = Sheet2.[E3].Value
Dim ToPRNo As String: ToPRNo = Sheet2.[F3].Value


Application.ScreenUpdating = False


With Sheet1.[A1].CurrentRegion
.AutoFilter 3, ">=" & fromPRNo, xlAnd, "<=" & ToPRNo

.Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)



.AutoFilter
End With

Sheet2.Columns.AutoFit

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe send those values to a different cell, then check if they don't equal before continuing.....
VBA Code:
Dim fromPRNo As String: fromPRNo = Sheet2.[E3].Value

Dim ToPRNo  As String: ToPRNo = Sheet2.[F3].Value

Application.ScreenUpdating = FALSE

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

If Sheet2.[Z3].Value<>fromPRNo And Sheet2.[AA3].Value<>ToPRNo Then
    
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    With Sheet1.[A1].CurrentRegion
        
        .AutoFilter 3, ">=" & fromPRNo, xlAnd, "<=" & ToPRNo
        
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
        
        .AutoFilter
        
    End With
    
    Sheet2.Columns.AutoFit
    
    '<<<<<<<<<<<<<<<<
    
    Sheet2.[Z3].Value=fromPRNo
    
    Sheet2.[AA3].Value=ToPRNo
    
    '>>>>>>>>>>>>>>>>>
    
    Application.ScreenUpdating = TRUE
    
    '<<<<<<<<<<<<<
    
End If

'>>>>>>>>>>>>>>>>

End Sub
 
Upvote 0
Maybe send those values to a different cell, then check if they don't equal before continuing.....
VBA Code:
Dim fromPRNo As String: fromPRNo = Sheet2.[E3].Value

Dim ToPRNo  As String: ToPRNo = Sheet2.[F3].Value

Application.ScreenUpdating = FALSE

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

If Sheet2.[Z3].Value<>fromPRNo And Sheet2.[AA3].Value<>ToPRNo Then
   
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
   
    With Sheet1.[A1].CurrentRegion
       
        .AutoFilter 3, ">=" & fromPRNo, xlAnd, "<=" & ToPRNo
       
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
       
        .AutoFilter
       
    End With
   
    Sheet2.Columns.AutoFit
   
    '<<<<<<<<<<<<<<<<
   
    Sheet2.[Z3].Value=fromPRNo
   
    Sheet2.[AA3].Value=ToPRNo
   
    '>>>>>>>>>>>>>>>>>
   
    Application.ScreenUpdating = TRUE
   
    '<<<<<<<<<<<<<
   
End If

'>>>>>>>>>>>>>>>>

End Sub

Dear friend, Thanks for your help but it is still copying the same PRno data which is already copied, It should not copy the same data again in that sheet..
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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