+ Reply to Thread
Results 1 to 8 of 8

Copy rows with a specific value in column A

  1. #1
    Gert-Jan
    Guest

    Copy rows with a specific value in column A

    Hi, this macro is supposed to copy all the rows with a specific value (in
    C25) to another sheet. But, only the first row will be copied. Can someone
    help?? Or have a better suggestion??

    Sub Copy()
    Application.ScreenUpdating = False
    With Sheets("Sheet1")
    Dim i As Long, sTargetValue As String
    sTargetValue = Sheets("Sheet1").Range("C25")
    For i = 100 To 1 Step -1
    If Cells(i, "A").Text = sTargetValue Then
    Rows(i).Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    SkipBlanks _
    :=False, Transpose:=False
    Sheets("Sheet1").Select
    End If
    Next i
    End With
    End Sub



  2. #2
    Don Guillett
    Guest

    Re: Copy rows with a specific value in column A

    I would suggest using data>filter>autofilter>filter on your value>copy the
    bunch at once but
    something like this without selections or screen updating needed. UNTESTED

    for i 100 to 2 step-1
    with sheets("sheet1")
    str = .Range("C25")
    dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    if .cells(i,"a")=strval then sheets("dest").rows(dlr).value=.rows(i).value
    next i
    end with


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Gert-Jan" <[email protected]> wrote in message
    news:[email protected]...
    > Hi, this macro is supposed to copy all the rows with a specific value (in
    > C25) to another sheet. But, only the first row will be copied. Can someone
    > help?? Or have a better suggestion??
    >
    > Sub Copy()
    > Application.ScreenUpdating = False
    > With Sheets("Sheet1")
    > Dim i As Long, sTargetValue As String
    > sTargetValue = Sheets("Sheet1").Range("C25")
    > For i = 100 To 1 Step -1
    > If Cells(i, "A").Text = sTargetValue Then
    > Rows(i).Select
    > Selection.Copy
    > Sheets("Sheet2").Select
    > Range("A1").Select
    > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    > SkipBlanks _
    > :=False, Transpose:=False
    > Sheets("Sheet1").Select
    > End If
    > Next i
    > End With
    > End Sub
    >




  3. #3
    Gert-Jan
    Guest

    Re: Copy rows with a specific value in column A

    Hi Don,

    Thanks for responding. Unfortunally, it doesn´t work: on "Str" I got an
    error.

    Gert-Jan

    "Don Guillett" <[email protected]> schreef in bericht
    news:%[email protected]...
    >I would suggest using data>filter>autofilter>filter on your value>copy the
    >bunch at once but
    > something like this without selections or screen updating needed. UNTESTED
    >
    > for i 100 to 2 step-1
    > with sheets("sheet1")
    > str = .Range("C25")
    > dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    > if .cells(i,"a")=strval then sheets("dest").rows(dlr).value=.rows(i).value
    > next i
    > end with
    >
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "Gert-Jan" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hi, this macro is supposed to copy all the rows with a specific value (in
    >> C25) to another sheet. But, only the first row will be copied. Can
    >> someone help?? Or have a better suggestion??
    >>
    >> Sub Copy()
    >> Application.ScreenUpdating = False
    >> With Sheets("Sheet1")
    >> Dim i As Long, sTargetValue As String
    >> sTargetValue = Sheets("Sheet1").Range("C25")
    >> For i = 100 To 1 Step -1
    >> If Cells(i, "A").Text = sTargetValue Then
    >> Rows(i).Select
    >> Selection.Copy
    >> Sheets("Sheet2").Select
    >> Range("A1").Select
    >> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    >> SkipBlanks _
    >> :=False, Transpose:=False
    >> Sheets("Sheet1").Select
    >> End If
    >> Next i
    >> End With
    >> End Sub
    >>

    >
    >






  4. #4
    Don Guillett
    Guest

    Re: Copy rows with a specific value in column A

    correct my typo so that str and strval are the same

    for i 100 to 2 step-1
    with sheets("sheet1")
    str = .Range("C25")
    dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    if .cells(i,"a")=str then sheets("dest").rows(dlr).value=.rows(i).value
    next i
    end with


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Gert-Jan" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Don,
    >
    > Thanks for responding. Unfortunally, it doesn´t work: on "Str" I got an
    > error.
    >
    > Gert-Jan
    >
    > "Don Guillett" <[email protected]> schreef in bericht
    > news:%[email protected]...
    >>I would suggest using data>filter>autofilter>filter on your value>copy the
    >>bunch at once but
    >> something like this without selections or screen updating needed.
    >> UNTESTED
    >>
    >> for i 100 to 2 step-1
    >> with sheets("sheet1")
    >> str = .Range("C25")
    >> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >> if .cells(i,"a")=strval then
    >> sheets("dest").rows(dlr).value=.rows(i).value
    >> next i
    >> end with
    >>
    >>
    >> --
    >> Don Guillett
    >> SalesAid Software
    >> [email protected]
    >> "Gert-Jan" <[email protected]> wrote in message
    >> news:[email protected]...
    >>> Hi, this macro is supposed to copy all the rows with a specific value
    >>> (in
    >>> C25) to another sheet. But, only the first row will be copied. Can
    >>> someone help?? Or have a better suggestion??
    >>>
    >>> Sub Copy()
    >>> Application.ScreenUpdating = False
    >>> With Sheets("Sheet1")
    >>> Dim i As Long, sTargetValue As String
    >>> sTargetValue = Sheets("Sheet1").Range("C25")
    >>> For i = 100 To 1 Step -1
    >>> If Cells(i, "A").Text = sTargetValue Then
    >>> Rows(i).Select
    >>> Selection.Copy
    >>> Sheets("Sheet2").Select
    >>> Range("A1").Select
    >>> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    >>> SkipBlanks _
    >>> :=False, Transpose:=False
    >>> Sheets("Sheet1").Select
    >>> End If
    >>> Next i
    >>> End With
    >>> End Sub
    >>>

    >>
    >>

    >
    >
    >
    >




  5. #5
    Gert-Jan
    Guest

    Re: Copy rows with a specific value in column A

    Hi,

    Thanks again. Made your macro "working" (read: error-free) with this:

    Sub Kopieren()
    For i = 100 To 2 Step -1
    With Sheets("Blad1")
    Strval = .Range("C26")
    dlr = Sheets("Blad2").Cells(Rows.Count, "a").End(xlUp).Row
    If .Cells(i, "a") = Strval Then Sheets("Blad2").Rows(dlr).Value =
    ..Rows(i).Value
    End With
    Next i
    End Sub

    But it has the same problem: it only copies the first line of my range.


    "Don Guillett" <[email protected]> schreef in bericht
    news:[email protected]...
    > correct my typo so that str and strval are the same
    >
    > for i 100 to 2 step-1
    > with sheets("sheet1")
    > str = .Range("C25")
    > dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    > if .cells(i,"a")=str then sheets("dest").rows(dlr).value=.rows(i).value
    > next i
    > end with
    >
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "Gert-Jan" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hi Don,
    >>
    >> Thanks for responding. Unfortunally, it doesn´t work: on "Str" I got an
    >> error.
    >>
    >> Gert-Jan
    >>
    >> "Don Guillett" <[email protected]> schreef in bericht
    >> news:%[email protected]...
    >>>I would suggest using data>filter>autofilter>filter on your value>copy
    >>>the
    >>>bunch at once but
    >>> something like this without selections or screen updating needed.
    >>> UNTESTED
    >>>
    >>> for i 100 to 2 step-1
    >>> with sheets("sheet1")
    >>> str = .Range("C25")
    >>> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >>> if .cells(i,"a")=strval then
    >>> sheets("dest").rows(dlr).value=.rows(i).value
    >>> next i
    >>> end with
    >>>
    >>>
    >>> --
    >>> Don Guillett
    >>> SalesAid Software
    >>> [email protected]
    >>> "Gert-Jan" <[email protected]> wrote in message
    >>> news:[email protected]...
    >>>> Hi, this macro is supposed to copy all the rows with a specific value
    >>>> (in
    >>>> C25) to another sheet. But, only the first row will be copied. Can
    >>>> someone help?? Or have a better suggestion??
    >>>>
    >>>> Sub Copy()
    >>>> Application.ScreenUpdating = False
    >>>> With Sheets("Sheet1")
    >>>> Dim i As Long, sTargetValue As String
    >>>> sTargetValue = Sheets("Sheet1").Range("C25")
    >>>> For i = 100 To 1 Step -1
    >>>> If Cells(i, "A").Text = sTargetValue Then
    >>>> Rows(i).Select
    >>>> Selection.Copy
    >>>> Sheets("Sheet2").Select
    >>>> Range("A1").Select
    >>>> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    >>>> SkipBlanks _
    >>>> :=False, Transpose:=False
    >>>> Sheets("Sheet1").Select
    >>>> End If
    >>>> Next i
    >>>> End With
    >>>> End Sub
    >>>>
    >>>
    >>>

    >>
    >>
    >>
    >>

    >
    >




  6. #6
    Don Guillett
    Guest

    Re: Copy rows with a specific value in column A

    tested

    Sub Kopieren()
    With Sheets("Blad1")
    For i = .Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
    dlr = Sheets("Blad2"). _
    Cells(Rows.Count, "a").End(xlUp).Row + 1
    Strval = .Range("C26")
    If .Cells(i, "a") = Strval Then _
    Sheets("Blad2").Rows(dlr).Value = .Rows(i).Value
    Next i
    End With
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Gert-Jan" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > Thanks again. Made your macro "working" (read: error-free) with this:
    >
    > Sub Kopieren()
    > For i = 100 To 2 Step -1
    > With Sheets("Blad1")
    > Strval = .Range("C26")
    > dlr = Sheets("Blad2").Cells(Rows.Count, "a").End(xlUp).Row
    > If .Cells(i, "a") = Strval Then Sheets("Blad2").Rows(dlr).Value =
    > .Rows(i).Value
    > End With
    > Next i
    > End Sub
    >
    > But it has the same problem: it only copies the first line of my range.
    >
    >
    > "Don Guillett" <[email protected]> schreef in bericht
    > news:[email protected]...
    >> correct my typo so that str and strval are the same
    >>
    >> for i 100 to 2 step-1
    >> with sheets("sheet1")
    >> str = .Range("C25")
    >> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >> if .cells(i,"a")=str then sheets("dest").rows(dlr).value=.rows(i).value
    >> next i
    >> end with
    >>
    >>
    >> --
    >> Don Guillett
    >> SalesAid Software
    >> [email protected]
    >> "Gert-Jan" <[email protected]> wrote in message
    >> news:[email protected]...
    >>> Hi Don,
    >>>
    >>> Thanks for responding. Unfortunally, it doesn´t work: on "Str" I got an
    >>> error.
    >>>
    >>> Gert-Jan
    >>>
    >>> "Don Guillett" <[email protected]> schreef in bericht
    >>> news:%[email protected]...
    >>>>I would suggest using data>filter>autofilter>filter on your value>copy
    >>>>the
    >>>>bunch at once but
    >>>> something like this without selections or screen updating needed.
    >>>> UNTESTED
    >>>>
    >>>> for i 100 to 2 step-1
    >>>> with sheets("sheet1")
    >>>> str = .Range("C25")
    >>>> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >>>> if .cells(i,"a")=strval then
    >>>> sheets("dest").rows(dlr).value=.rows(i).value
    >>>> next i
    >>>> end with
    >>>>
    >>>>
    >>>> --
    >>>> Don Guillett
    >>>> SalesAid Software
    >>>> [email protected]
    >>>> "Gert-Jan" <[email protected]> wrote in message
    >>>> news:[email protected]...
    >>>>> Hi, this macro is supposed to copy all the rows with a specific value
    >>>>> (in
    >>>>> C25) to another sheet. But, only the first row will be copied. Can
    >>>>> someone help?? Or have a better suggestion??
    >>>>>
    >>>>> Sub Copy()
    >>>>> Application.ScreenUpdating = False
    >>>>> With Sheets("Sheet1")
    >>>>> Dim i As Long, sTargetValue As String
    >>>>> sTargetValue = Sheets("Sheet1").Range("C25")
    >>>>> For i = 100 To 1 Step -1
    >>>>> If Cells(i, "A").Text = sTargetValue Then
    >>>>> Rows(i).Select
    >>>>> Selection.Copy
    >>>>> Sheets("Sheet2").Select
    >>>>> Range("A1").Select
    >>>>> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    >>>>> SkipBlanks _
    >>>>> :=False, Transpose:=False
    >>>>> Sheets("Sheet1").Select
    >>>>> End If
    >>>>> Next i
    >>>>> End With
    >>>>> End Sub
    >>>>>
    >>>>
    >>>>
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >
    >




  7. #7
    Gert-Jan
    Guest

    Re: Copy rows with a specific value in column A

    Thanks, works great!

    "Don Guillett" <[email protected]> schreef in bericht
    news:[email protected]...
    > tested
    >
    > Sub Kopieren()
    > With Sheets("Blad1")
    > For i = .Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
    > dlr = Sheets("Blad2"). _
    > Cells(Rows.Count, "a").End(xlUp).Row + 1
    > Strval = .Range("C26")
    > If .Cells(i, "a") = Strval Then _
    > Sheets("Blad2").Rows(dlr).Value = .Rows(i).Value
    > Next i
    > End With
    > End Sub
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "Gert-Jan" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hi,
    >>
    >> Thanks again. Made your macro "working" (read: error-free) with this:
    >>
    >> Sub Kopieren()
    >> For i = 100 To 2 Step -1
    >> With Sheets("Blad1")
    >> Strval = .Range("C26")
    >> dlr = Sheets("Blad2").Cells(Rows.Count, "a").End(xlUp).Row
    >> If .Cells(i, "a") = Strval Then Sheets("Blad2").Rows(dlr).Value =
    >> .Rows(i).Value
    >> End With
    >> Next i
    >> End Sub
    >>
    >> But it has the same problem: it only copies the first line of my range.
    >>
    >>
    >> "Don Guillett" <[email protected]> schreef in bericht
    >> news:[email protected]...
    >>> correct my typo so that str and strval are the same
    >>>
    >>> for i 100 to 2 step-1
    >>> with sheets("sheet1")
    >>> str = .Range("C25")
    >>> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >>> if .cells(i,"a")=str then sheets("dest").rows(dlr).value=.rows(i).value
    >>> next i
    >>> end with
    >>>
    >>>
    >>> --
    >>> Don Guillett
    >>> SalesAid Software
    >>> [email protected]
    >>> "Gert-Jan" <[email protected]> wrote in message
    >>> news:[email protected]...
    >>>> Hi Don,
    >>>>
    >>>> Thanks for responding. Unfortunally, it doesn´t work: on "Str" I got an
    >>>> error.
    >>>>
    >>>> Gert-Jan
    >>>>
    >>>> "Don Guillett" <[email protected]> schreef in bericht
    >>>> news:%[email protected]...
    >>>>>I would suggest using data>filter>autofilter>filter on your value>copy
    >>>>>the
    >>>>>bunch at once but
    >>>>> something like this without selections or screen updating needed.
    >>>>> UNTESTED
    >>>>>
    >>>>> for i 100 to 2 step-1
    >>>>> with sheets("sheet1")
    >>>>> str = .Range("C25")
    >>>>> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >>>>> if .cells(i,"a")=strval then
    >>>>> sheets("dest").rows(dlr).value=.rows(i).value
    >>>>> next i
    >>>>> end with
    >>>>>
    >>>>>
    >>>>> --
    >>>>> Don Guillett
    >>>>> SalesAid Software
    >>>>> [email protected]
    >>>>> "Gert-Jan" <[email protected]> wrote in message
    >>>>> news:[email protected]...
    >>>>>> Hi, this macro is supposed to copy all the rows with a specific value
    >>>>>> (in
    >>>>>> C25) to another sheet. But, only the first row will be copied. Can
    >>>>>> someone help?? Or have a better suggestion??
    >>>>>>
    >>>>>> Sub Copy()
    >>>>>> Application.ScreenUpdating = False
    >>>>>> With Sheets("Sheet1")
    >>>>>> Dim i As Long, sTargetValue As String
    >>>>>> sTargetValue = Sheets("Sheet1").Range("C25")
    >>>>>> For i = 100 To 1 Step -1
    >>>>>> If Cells(i, "A").Text = sTargetValue Then
    >>>>>> Rows(i).Select
    >>>>>> Selection.Copy
    >>>>>> Sheets("Sheet2").Select
    >>>>>> Range("A1").Select
    >>>>>> Selection.PasteSpecial Paste:=xlPasteValues,
    >>>>>> Operation:=xlNone,
    >>>>>> SkipBlanks _
    >>>>>> :=False, Transpose:=False
    >>>>>> Sheets("Sheet1").Select
    >>>>>> End If
    >>>>>> Next i
    >>>>>> End With
    >>>>>> End Sub
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




  8. #8
    Don Guillett
    Guest

    Re: Copy rows with a specific value in column A

    glad to help

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Gert-Jan" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks, works great!
    >
    > "Don Guillett" <[email protected]> schreef in bericht
    > news:[email protected]...
    >> tested
    >>
    >> Sub Kopieren()
    >> With Sheets("Blad1")
    >> For i = .Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
    >> dlr = Sheets("Blad2"). _
    >> Cells(Rows.Count, "a").End(xlUp).Row + 1
    >> Strval = .Range("C26")
    >> If .Cells(i, "a") = Strval Then _
    >> Sheets("Blad2").Rows(dlr).Value = .Rows(i).Value
    >> Next i
    >> End With
    >> End Sub
    >>
    >> --
    >> Don Guillett
    >> SalesAid Software
    >> [email protected]
    >> "Gert-Jan" <[email protected]> wrote in message
    >> news:[email protected]...
    >>> Hi,
    >>>
    >>> Thanks again. Made your macro "working" (read: error-free) with this:
    >>>
    >>> Sub Kopieren()
    >>> For i = 100 To 2 Step -1
    >>> With Sheets("Blad1")
    >>> Strval = .Range("C26")
    >>> dlr = Sheets("Blad2").Cells(Rows.Count, "a").End(xlUp).Row
    >>> If .Cells(i, "a") = Strval Then Sheets("Blad2").Rows(dlr).Value =
    >>> .Rows(i).Value
    >>> End With
    >>> Next i
    >>> End Sub
    >>>
    >>> But it has the same problem: it only copies the first line of my range.
    >>>
    >>>
    >>> "Don Guillett" <[email protected]> schreef in bericht
    >>> news:[email protected]...
    >>>> correct my typo so that str and strval are the same
    >>>>
    >>>> for i 100 to 2 step-1
    >>>> with sheets("sheet1")
    >>>> str = .Range("C25")
    >>>> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >>>> if .cells(i,"a")=str then sheets("dest").rows(dlr).value=.rows(i).value
    >>>> next i
    >>>> end with
    >>>>
    >>>>
    >>>> --
    >>>> Don Guillett
    >>>> SalesAid Software
    >>>> [email protected]
    >>>> "Gert-Jan" <[email protected]> wrote in message
    >>>> news:[email protected]...
    >>>>> Hi Don,
    >>>>>
    >>>>> Thanks for responding. Unfortunally, it doesn´t work: on "Str" I got
    >>>>> an error.
    >>>>>
    >>>>> Gert-Jan
    >>>>>
    >>>>> "Don Guillett" <[email protected]> schreef in bericht
    >>>>> news:%[email protected]...
    >>>>>>I would suggest using data>filter>autofilter>filter on your value>copy
    >>>>>>the
    >>>>>>bunch at once but
    >>>>>> something like this without selections or screen updating needed.
    >>>>>> UNTESTED
    >>>>>>
    >>>>>> for i 100 to 2 step-1
    >>>>>> with sheets("sheet1")
    >>>>>> str = .Range("C25")
    >>>>>> dlr=sheets("dest").cells(rows.count,"a").end(xlup).row
    >>>>>> if .cells(i,"a")=strval then
    >>>>>> sheets("dest").rows(dlr).value=.rows(i).value
    >>>>>> next i
    >>>>>> end with
    >>>>>>
    >>>>>>
    >>>>>> --
    >>>>>> Don Guillett
    >>>>>> SalesAid Software
    >>>>>> [email protected]
    >>>>>> "Gert-Jan" <[email protected]> wrote in message
    >>>>>> news:[email protected]...
    >>>>>>> Hi, this macro is supposed to copy all the rows with a specific
    >>>>>>> value (in
    >>>>>>> C25) to another sheet. But, only the first row will be copied. Can
    >>>>>>> someone help?? Or have a better suggestion??
    >>>>>>>
    >>>>>>> Sub Copy()
    >>>>>>> Application.ScreenUpdating = False
    >>>>>>> With Sheets("Sheet1")
    >>>>>>> Dim i As Long, sTargetValue As String
    >>>>>>> sTargetValue = Sheets("Sheet1").Range("C25")
    >>>>>>> For i = 100 To 1 Step -1
    >>>>>>> If Cells(i, "A").Text = sTargetValue Then
    >>>>>>> Rows(i).Select
    >>>>>>> Selection.Copy
    >>>>>>> Sheets("Sheet2").Select
    >>>>>>> Range("A1").Select
    >>>>>>> Selection.PasteSpecial Paste:=xlPasteValues,
    >>>>>>> Operation:=xlNone,
    >>>>>>> SkipBlanks _
    >>>>>>> :=False, Transpose:=False
    >>>>>>> Sheets("Sheet1").Select
    >>>>>>> End If
    >>>>>>> Next i
    >>>>>>> End With
    >>>>>>> End Sub
    >>>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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