+ Reply to Thread
Results 1 to 3 of 3

An easier macro to Copy value in cell c if valule in b =no.

Hybrid View

  1. #1
    Registered User
    Join Date
    01-15-2020
    Location
    London
    MS-Off Ver
    Office 15
    Posts
    1

    An easier macro to Copy value in cell c if valule in b =no.

    I am doing a quality check sheet for work and if say if any cells in Column B contain "no" in them i need the corresponding cell to in Column C to be copied on to a seperate sheet starting in a specific row then going down for every row where there is data.

    I.E. Cell B3 = no Cell C is copied "wrong date entered" and pasted on Results Sheet in cell A7 and so on.

    Have got it working looking like this

    Sheets("Checking Sheet").Select
    If Range("$B3") = "No" Then
    Range("$C3").copy
    Sheets("Results Sheet").Select
    Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    End If
    Sheets("Checking Sheet").Select
    If Range("$B4") = "No" Then
    Range("$C4").copy
    Sheets("Results Sheet").Select
    Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    End If
    Sheets("Checking Sheet").Select
    If Range("$B5") = "No" Then
    Range("$C5").copy
    Sheets("Results Sheet").Select
    Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    End If

    However pretty sure there has to be an easier way of doing it as don't fancy doing the whole macro like this as there is about 63 cells.

    Any help would be appreciated.

    thanks

  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: An easier macro to Copy value in cell c if valule in b =no.

    Try this:

    Sub Whatever(): Dim wc As Worksheet, wr As Worksheet, r As Long, c As Long
    Set wc = Sheets("Checking Sheet"): Set wr = Sheets("Results Sheet")
    r = wr.Range("A" & Rows.count).End(xlUp).Row + 1
    For c = 3 To wc.Range("B" & Rows.count).End(xlUp).Row
    If LCase(wc.Cells(c, 2)) = "no" Then wc.Cells(c, 3).Copy wr.Cells(r, 1)
    r = r + 1: Next c: End Sub
    BTW:Administrative Note:

    Welcome to the forum.

    You need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Please attend to this as I should not have offered any code.
    Last edited by xladept; 01-16-2020 at 01:20 AM.
    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
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: An easier macro to Copy value in cell c if valule in b =no.

    Another option. I'm assuming there's a column label in B1 on the Checking Sheet

    Sub CopyNos()
        With Sheets("Checking Sheet").Range("B1")
            .CurrentRegion.AutoFilter field:=1, Criteria1:="no"
            .CurrentRegion.Offset(1, 1).Resize(, 1).SpecialCells(xlCellTypeVisible).Copy Sheets("Results Sheet").Range("A" & Rows.Count).End(xlUp).Cells(2, 1)
        End With
    
    
    End Sub
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. pie chart no show zero valule
    By kmaloney01 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-06-2018, 08:05 AM
  2. Easier way to match and copy data
    By 0rganiser in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-17-2015, 04:51 PM
  3. Is there an easier way to copy a cell from another sheet
    By Larbec in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-27-2015, 02:41 PM
  4. Return a numberic valule based on text
    By Mechjo16 in forum Excel General
    Replies: 1
    Last Post: 05-15-2015, 09:15 AM
  5. [SOLVED] Make Copy code easier
    By Shimazu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2014, 06:01 AM
  6. Copy valule from one column and then paste only blank cell to other worksheet
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2013, 12:42 PM
  7. CountIf with valule critera?
    By bw26934 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-17-2008, 12:48 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