+ Reply to Thread
Results 1 to 2 of 2

To copy an entire row to an other sheet if a cell meets a criteria

  1. #1
    Registered User
    Join Date
    11-14-2014
    Location
    Umeå
    MS-Off Ver
    Windows 7
    Posts
    1

    To copy an entire row to an other sheet if a cell meets a criteria

    Hi,

    I'm a beginner and I don't know what I'm doing, but I would need some help with coding a macro which copies a whole row if a specific cell in this row meets a criteria.

    So, in Column H I have values ">12 months" and "<12 months" to get information of the length of a contract. If this cell takes value "<12 months" I want excel to copy the entire row to Sheet 2. I have googled a bit but this is what I've done this far:

    Option Explicit
    Private Sub Worksheet_change(ByVal Target As Range)
    Dim nxtRow As Integer, b As Boolean
    Dim H2 As Range
    If Target.Column = 8 Then
    If Target.Value = "<12 months" Then
    b = True
    Else
    b = False
    End If
    End If

    If b Then
    nxtRow = Sheets(2).Range("H" & Rows.Count).End(xlUp)
    Target.EntireRow.Copy_
    Destination = Sheets(2).Range("A" & nxtRow)
    End If
    End Sub

    But something is wrong, Excel doesn't read this as an macro, every time I try to play the macro Excel gives me an opinion to write it again? The problem seems to be in the first rows "Option Explicit
    Private Sub Worksheet_change(ByVal Target As Range)"

    Can somebody help me to write the code that it works? Can you see what is wrong with it? I studied VBA two weeks at Uni and it didn't give me much more than really basics.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: To copy an entire row to an other sheet if a cell meets a criteria

    Please use code tags with your code.
    The values you are looking for may be are numbers.
    Try one of these lines
    Please Login or Register  to view this content.

+ 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] Copying entire rows of data if a cell meets certain criteria
    By dmchase in forum Excel General
    Replies: 7
    Last Post: 04-06-2016, 09:24 AM
  2. Copy text from one sheet to another if one cell meets criteria
    By dptiedtke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-11-2014, 06:20 AM
  3. Copy entire row to a different sheet's first emtpy row if a cell meets a criteria
    By Blaise930 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-13-2013, 12:41 PM
  4. [SOLVED] copy select columns instead of entire row if it meets specific criteria
    By liz80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-18-2012, 04:26 PM
  5. Replies: 3
    Last Post: 01-24-2011, 08:35 PM

Tags for this Thread

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