+ Reply to Thread
Results 1 to 13 of 13

VBA to find value anc create entire row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    VBA to find value anc create entire row

    Good day to all.

    I need a macro that will search a value in column D (sheet2) that is noted in cell C7 on sheet3.
    Afterthat it must copy enitre entire row where searched value was found to sheet3, last empty row.

    an example:

    entered value in cell C7 on sheet 3 is ABC
    on Sheet2 column D, value ABC was found in cell 150 (D150) so it has to copy for 150 to sheet3, last empy row.

    How to od it?

    Thanks.

  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: VBA to find value anc create entire row

    Maybe:

    Sub forfiettYY()
    Dim x As String
    x = Sheets("Sheet3").Range("C7").Value
    Sheets("Sheet2").Columns(4).Cells.Find(What:=x, After:=Cells(1, 4), LookIn:=xlFormulas, lookat:=xlPart, Searchorder:=xlByRows, searchDirection:=xlNext, MatchCase:=False).Activate
    Rows(ActiveCell.Row).Copy Sheets("Sheet3").Range("A" & Rows.count).End(3)(2)
    End Sub

  3. #3
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    Good day,

    thanks for quick reply but is not working for me....
    any other option?

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

    Re: VBA to find value anc create entire row

    Option Explicit
    
    Sub fin()
    Dim Rng As Range, x, ms As Worksheet
    Set ms = Sheets("Sheet3")
    x = ms.Range("C7").Value
    Application.ScreenUpdating = 0
                 With Sheets("Sheet2").Columns(4)
                         Set Rng = .Find(x, LookIn:=xlValues, LookAt:=xlWhole)
                            If Not Rng Is Nothing Then
                                Rng.EntireRow.Copy
                                ms.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
                            End If
                 End With
         
        
         Application.CutCopyMode = 0
    
    Set Rng = Nothing
    Set ms = Nothing
    
    Application.ScreenUpdating = True
    End Sub

  5. #5
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    perfect! for now is working ..
    will revert if any additional option will be needed.
    THANKS

  6. #6
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    Dears,

    it is possible to ammend above code that will not copy entire row but only fm colum A to M

    Thanks in advance

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

    Re: VBA to find value anc create entire row

    Rng.EntireRow.Copy
    
    INTO
    
    Rng.Offset(, -3).Resize(, 13).Copy
    Please close the thread now as solved

  8. #8
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    Dears,

    it is possible to ammend bellow code so that if searched value in column will appear more times that will copy all rows where searched value is found??

    Best ragards,
    forfiett
    Last edited by forfiett; 08-20-2014 at 08:42 AM.

  9. #9
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    Normally, same values are in a sequence in a column.

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

    Re: VBA to find value anc create entire row

    fortfiett,
    This thread is over a month old. If you do not close it, it will go for ever. The forum has designed in such away that a thread must be closed at some point. You can start a new thread, linking it with the old thread.
    Please mark the thread as solved. If you have further questions, you should start a new thread.

    Option Explicit
    
    Sub fin()
    Dim Rng As Range, x, ms As Worksheet, FirstAddress$
    Set ms = Sheets("Sheet3")
    x = ms.Range("C7").Value
    Application.ScreenUpdating = 0
                 With Sheets("Sheet2").Columns(4)
                         Set Rng = .Find(x, LookIn:=xlValues, LookAt:=xlWhole)
                            If Not Rng Is Nothing Then
                            FirstAddress = Rng.Address
                            Do
                                Rng.Offset(, -3).Resize(, 13).Copy
                                ms.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
                                 Set Rng = .FindNext(Rng)
                            Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
                            End If
                 End With
         
        
         Application.CutCopyMode = 0
    
    Set Rng = Nothing
    Set ms = Nothing
    
    Application.ScreenUpdating = True
    End Sub

  11. #11
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    Dear,

    it was marked a solved, but i need firther assistance so i unmarked it..

    thanks for code but is not working...

    please check: Rng.Offset(, -3).Resize(, 13).Copy

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

    Re: VBA to find value anc create entire row

    I have got the line from post#7.

  13. #13
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: VBA to find value anc create entire row

    Finally it is working. Thanks.

    Marked as solved.

+ 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. Create a GUID in entire column
    By tvainisi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-07-2013, 06:04 PM
  2. Trying to Create a Macro that Applies to Entire Columns
    By JEdel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2013, 04:41 PM
  3. Replies: 3
    Last Post: 11-12-2012, 10:33 AM
  4. How to create a graph with values from an entire column
    By icedTea89 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-15-2012, 07:30 AM
  5. How do I create a formula for an entire column
    By Shelly9633 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-01-2005, 07:05 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