+ Reply to Thread
Results 1 to 8 of 8

Copy paste to another sheet only once when the condition is met

Hybrid View

ecelebi16 Copy paste to another sheet... 09-09-2019, 09:15 AM
bulina2k Re: Copy paste to another... 09-09-2019, 09:23 AM
PaulM100 Re: Copy paste to another... 09-09-2019, 09:27 AM
ecelebi16 Re: Copy paste to another... 09-09-2019, 10:00 AM
Sintek Re: Copy paste to another... 09-09-2019, 10:03 AM
ecelebi16 Re: Copy paste to another... 09-09-2019, 10:25 AM
6StringJazzer Re: Copy paste to another... 09-09-2019, 10:32 AM
PaulM100 Re: Copy paste to another... 09-09-2019, 11:11 AM
  1. #1
    Registered User
    Join Date
    09-09-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    3

    Copy paste to another sheet only once when the condition is met

    Hello,

    I am trying to improve a tracking a sheet that we go in once a while and update the conditions. If the condition is 1 (meaning 100) then we want to paste into the "Wins" sheet for the selected ranges. The code I have works to paste the entire data when the condition is met, but when I click on the button to update, then it updates everything all over again. I would like to have it updated only once and the next available empty row on "Wins" sheet.

    I tried two things:
    1) this one runs and copies all the data
    Private Sub CommandButton1_Click()
    
    a = Worksheets("IC Pipeline").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To a
    
      If Worksheets("IC Pipeline").Cells(i, 11).Value = "1" Then
         Worksheets("IC Pipeline").Rows(i).Copy
         Worksheets("Wins").Activate
         b = Worksheets("Wins").Cells(Rows.Count, 1).End(xlUp).Row
         Worksheets("Wins").Cells(b + 1, 1).Select
         ActiveSheet.Paste
              Worksheets("IC Pipeline").Activate
         End If
         
         Next
         
         Application.CutCopyMode = False
         
         ThisWorkbook.Worksheets("IC Pipeline").Cells(1, 1).Select
         
    End Sub
    2) This one gives me an error "Wrong number of arguments or invalid property assignment"
    Private Sub CommandButton2_Click()
    
    Dim LastRow As Integer, i As Integer, erow As Integer
    
    LastRow = Worksheets("IC Pipeline").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To LastRow
    
        If Worksheets("IC Pipeline").Cells(i, 11).Value = "1" Then
        Range(Cells(i, 1), Cells(i, 2), Cells(i, 3), Cells(i, 4), Cells(i, 7), Cells(i, 8), Cells(i, 9), Cells(i, 10), Cells(i, 11), Cells(i, 12), Cells(i, 13), Cells(i, 14)).Select
        Selection.Copy
        Worksheets("Wins2").Activate
        erow = Worksheets("Wins2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        Worksheets("Wins2").Cells(erow, 1).Select
        ActiveSheet.Paste
        ThisWorkbook.Save
        Application.CutCopyMode = False
        End If
    
    Next i
    
    End Sub
    *********

    Can someone help me figure this out ??

    Thank you!
    ecelebi16
    Attached Files Attached Files
    Last edited by 6StringJazzer; 09-09-2019 at 10:32 AM.

  2. #2
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Copy paste to another sheet only once when the condition is met

    What do you want to copy to "WINS", only the last record in "IC Pipeline" or whatever is selected when you click on the button?
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  3. #3
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Copy paste to another sheet only once when the condition is met

    Try this:
    Private Sub CommandButton1_Click()
    
    Dim a As Long
    Dim b As Long
    Dim wbS As Worksheet
    Dim wbD As Worksheet
    
    Set wbS = ThisWorkbook.Worksheets("IC Pipeline")
    Set wsd = ThisWorkbook.Worksheets("Wins")
    
    a = wbS.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To a
    
    If wbS.Cells(i, 11).Value = "1" Then
    wbS.Rows(i).Copy
    wsd.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    End If
    
    Next
    Worksheets("IC Pipeline").Activate
    End Sub
    Click the * to say thanks.

  4. #4
    Registered User
    Join Date
    09-09-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    3

    Re: Copy paste to another sheet only once when the condition is met

    Hi bulinak, I have added the attachment. So you see that column D, the probability gets updated when it is a win, meaning 100. So when I hit update it should add the data at the end of the wins tab when there is potential changes. This change is random, but I want that updated data to be at the end of the wins file when there is change.

    But coding updates everything every time when I hit update.

    Thank you!

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Copy paste to another sheet only once when the condition is met

    What about forum Rules here
    2. Programming code must be enclosed in code tags to improve readability. (A, Z)
     Your Code
    (or use the # button)

    '! No looping required...Use AutoFilter
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    09-09-2019
    Location
    USA
    MS-Off Ver
    2016
    Posts
    3

    Re: Copy paste to another sheet only once when the condition is met

    Hi PaulM100 , thanks for your response. I used your coding and it does the same thing.. When I go back for the second time, it updates the entire list again.. I only need to have it update it once the probability turns to 1. I attached my excel if you want to take a look at it.

    Thank you!

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Copy paste to another sheet only once when the condition is met

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. I have also noted that you ignored sintek's post about this. In the future that can earn warnings. --6StringJazzer
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  8. #8
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Copy paste to another sheet only once when the condition is met

    Then you don't need a button, you need it to trigger automatically on cell change. Right click on IC pipeline tab - view code and insert the following code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim wsCopy As Worksheet
        Dim rngCopy As Range
        Dim wsPaste As Worksheet
        Dim rngPaste As Range
        
        If Target.Column = 4 Then
        
            If Target.Value = "1" Then
                Set wsCopy = ActiveSheet
                Set wsPaste = ActiveWorkbook.Worksheets("Wins")
                Set rngCopy = wsCopy.Range("A" & Target.Row & ":U" & Target.Row)
                rngCopy.Select
                Set rngPaste = wsPaste.Range("A" & wsPaste.Range("A" & Rows.Count).End(xlUp).Row + 1)
                
                rngCopy.Copy
                rngPaste.PasteSpecial
                Application.CutCopyMode = False
                Set rngCopy = Nothing
                Set rngPaste = Nothing
                Set wsCopy = Nothing
                Set wsPaste = Nothing
            End If
        End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to use a For Loop to copy and paste to another sheet based on condition?
    By maym in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-15-2018, 10:31 PM
  2. [SOLVED] IF condition copy paste Range(ActiveCell.Offset(,) in new sheet
    By incobart in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 07-13-2017, 06:39 AM
  3. [SOLVED] Copy and paste (values) to another sheet based on condition
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-09-2013, 10:25 PM
  4. Replies: 1
    Last Post: 09-17-2013, 01:38 PM
  5. Macro to copy from one sheet and paste in another if a condition is met.
    By dlholland1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2013, 09:41 AM
  6. [SOLVED] Code to copy and paste a row into another sheet of the workbook when a condition is met.
    By oldboots in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2013, 03:03 AM
  7. Copy/Paste from one sheet to another based on condition
    By TheTempest in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-16-2010, 01:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1