+ Reply to Thread
Results 1 to 5 of 5

Code to check in cell equals a value, if true copy row.

Hybrid View

  1. #1
    Registered User
    Join Date
    09-15-2012
    Location
    London,England
    MS-Off Ver
    Excel 2003
    Posts
    15

    Code to check in cell equals a value, if true copy row.

    Hi all,
    I am having trouble thinking of a way to develope the following:

    I have an inventory sheet that originally some of you helped me with. I need to develope this further to check if the stock has reach minimum level, if so copy the entire row to another sheet.

    I have worked out to check the value in L5<=M5 then place a value of 1 in N5 if true.
    Now I am struggling to work out how to check if any cell in column N=1. If so copy the entire row and paste into sheet 3. Then check rest of the sheet.

    Can anyone heDatabase Min Max.xlsmlp?

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Code to check in cell equals a value, if true copy row.

    Hi Creeky,

    I think this is what you said:

    Sub Creeky(): Dim wa As Worksheet, wr As Worksheet, ws As Worksheet
    Set wa = Sheets("ALL STOCK NEW"): Set wr = Sheets("Stock Removed")
                    Set ws = Sheets("Stock <= Min")
    Dim a As Long, r As Long, s As Long: s = ws.Range("A" & Rows.Count).End(xlUp).row
    
    a = 2: Do Until wa.Range("N" & a) = ""
    If wa.Range("N" & a) = 1 Then
    s = s + 1: wa.Range("N" & a).EntireRow.Copy ws.Range("A" & s)
    End If: a = a + 1: Loop
    End Sub
    I'm not sure it's what you want??
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Code to check in cell equals a value, if true copy row.

    You can also try:

    Sub TransferInvetory()
    Dim r As Long, endRow As Long, pasteRowIndex As Long
    
    endRow = Range("A" & Rows.Count).End(xlUp).Row + 1
    pasteRowIndex = 1
    
    For r = 1 To endRow 'Loop through sheet1 and search for your criteria
    
        If Cells(r, Columns("L").Column).Value <= Cells(r, Columns("M").Column).Value Then 'Found
    
                'Copy the current row
                Rows(r).Select
                Selection.Cut
    
                'Switch to the sheet where you want to paste it & paste
                Sheets(3).Select
                Rows(Range("A" & Rows.Count).End(xlUp).Row + 1).Select
                ActiveSheet.Paste
    
                'Next time you find a match, it will be pasted in a new row
                pasteRowIndex = pasteRowIndex + 1
    
    
               'Switch back to your table Delete the row if found (Disabled by default)
                Sheets(1).Select
                'Rows(r).Delete
    
    'Continue to search for your criteria
        End If
    Next r
    
    MsgBox "Complete!"
    End Sub
    Last edited by playaller; 05-12-2014 at 07:21 PM.


    Shelton A.
    If Helpful, Add Reputaion!

  4. #4
    Registered User
    Join Date
    09-15-2012
    Location
    London,England
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Code to check in cell equals a value, if true copy row.

    Apologies. I thought I had already replied to this.

    Both work great. Thank you very much for your help.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Code to check in cell equals a value, if true copy row.

    Hi Creeky,

    You're welcome

+ 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] Code to copy data from another workbook where offset cell equals "none"
    By Nitefox in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-20-2014, 01:33 PM
  2. Check if a filename contains (not equals) the value of a cell
    By kevv in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2013, 10:27 AM
  3. Check if two cells are equal and copy,paste cell if true
    By solomeros in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2011, 01:22 AM
  4. Replies: 3
    Last Post: 05-29-2009, 05:42 AM
  5. Replies: 2
    Last Post: 05-29-2009, 04:35 AM

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