+ Reply to Thread
Results 1 to 12 of 12

Selective copying based on cell values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Question Selective copying based on cell values

    Hi,
    This thread has emerged from my previous unsuccessful thread. I have changed my approach. Hope this time it will work.

    In sheet1, I am trying to copy Certain cells or rows based on cell value in column K ( K 200 :K 305) if the value is equal to 1.... The respective rows or cells to be copied are from M200: S305.
    These are to be pasted to same sheet at columns A to G in the next free row available.

    I have tried various things and they don't work....
    The code that I would use is as follows:

    Sub_CopyOnlyOne()
    
        Dim sourceRng As Range
        Dim cell As Range
        Dim i As Long
    
        Set sourceRng = ActiveSheet.Range("K200:K305")
        i = 1
    
        For Each cell In sourceRng
            If cell.Value = 1 Then
                cell.Resize(1, 5).Copy Destination:=Range("A76:G190" & i)
                'this is a problem area
                i = i + 1
            End If
        Next cell
    
    End Sub
    I have attached the book as well....
    Many thanks

    Regards
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selective copying based on cell values

    Maybe:

    Sub KK1234()
    Dim i As Long
    For i = 200 To 305
        If Range("K" & i).Value = 1 Then
            Range(Range("K" & i).Offset(, 2), Range("K" & i).Offset(, 8)).Copy Range("A" & Rows.count).End(3)(2)
        End If
    Next i
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Selective copying based on cell values

    Hi John,
    Perfect solution. Thanks. I have clicked * to thanks you.
    May I also request you if I include any additional question on this ( related to change event or do you want me to post as a new thread?)
    Thanks again
    Regards

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selective copying based on cell values

    You're welcome. Glad to help out. Thanks for the feedback and the rep. I think it would be best for you to start a new thread for the change event question and mark this thread as solved. See Forum Rule 9 below.

    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

  5. #5
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Selective copying based on cell values

    Thanks John.
    I am closing this one as solved. and post another one.
    Thanks again for greate help
    Regards

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Selective copying based on cell values

    Perhaps this could also be a possible solution?

    Sub Another()
    
        Range("K200:S200").AutoFilter Field:=1, Criteria1:="1"
        AutoFilter.Range.Copy
        Range("A76").PasteSpecial Paste:=xlPasteAll
        AutoFilterMode = False
        Application.CutCopyMode = False
    
    End Sub
    Alf

  7. #7
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Selective copying based on cell values

    Hi Alf,
    Thanks for your help. Apology for a late reply.
    This does not work as intended.
    Steps that I want to achieve are...
    1. check range AF400:AF514 for any values of 1
    2. Then copy those respective rows ( from AH:AN), where value of respective AF cell is 1
    3. Paste it in range A:G in the next available row without loosing the reference
    ( right now John's code works very fine, however I am now getting REF errors )
    I have also requested John for more help.
    I will be very thankful if I am able to resolve it with both of your help...
    Thanks again
    kind regards

  8. #8
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Selective copying based on cell values

    Hi John and Alf,
    Any help yet
    please?
    Regards

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selective copying based on cell values

    Maybe:

    Sub KK1234z()
    Dim i As Long
    For i = 400 To 511
        If Range("AF" & i).Value = 0 Then
            Range("A" & Rows.count).End(3)(2).Resize(, 7).Value = Range(Range("AF" & i).Offset(, 2), Range("AF" & i).Offset(, 8)).Value
        End If
    Next i
    End Sub

  10. #10
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Selective copying based on cell values

    Hi John,
    Very well done sir.
    Wow.
    It now works great
    Apology that it took a while for me to understand.
    Thanks for your great support.
    Nice to interact with you John.
    Kind regards
    KK1234

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selective copying based on cell values

    Once again welcome. Glad to hear it worked for you. Sorry, it took so long too respond, but I've been offline for awhile.

  12. #12
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Selective copying based on cell values

    Thanks John again

+ 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. [SOLVED] Show the images based on the selective cell value
    By krishnakuma6 in forum Excel General
    Replies: 1
    Last Post: 11-12-2012, 06:21 AM
  2. Replies: 3
    Last Post: 06-06-2012, 05:36 AM
  3. Copying data to a table based on cell values
    By Miraun in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-27-2011, 09:19 AM
  4. Macro for copying and duplicating data based on a cell values.
    By outthere in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-25-2009, 12:31 PM
  5. How to add new data to existing cell based on multiple selective inputs?
    By AlphaSvn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2009, 06:08 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