+ Reply to Thread
Results 1 to 11 of 11

Search columns and paste rows

Hybrid View

  1. #1
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search columns and paste rows

    Welcome to the Board.

    Something along the lines of the below perhaps ?

    Public Sub FilterData()
    Dim rngArea As Range
    Sheets("sheet2").Columns(1).Clear
    Sheets("Sheet1").Select
    With Range(Cells(1, Columns.Count), Cells(Rows.Count, "A").End(xlUp).Offset(, Columns.Count - 1))
        .FormulaR1C1 = "=IF(AND(RC2=0,RC3<=0.1,RC4<=0.1),1,""x"")"
        For Each rngArea In .SpecialCells(xlCellTypeFormulas, xlNumbers).Areas
            Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(rngArea.Rows.Count).Value = rngArea.Offset(, 1 - Columns.Count).Value
        Next rngArea
        .Clear
    End With
    End Sub

  2. #2
    Registered User
    Join Date
    02-25-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Search columns and paste rows

    Thank you very much for your help DonkeyOte, worked perfectly.

    I now have a different but similar problem.

    I need to search Column B for the number 4 and then copy the values in Columns G,H,I and J into sheet 2.

    The attached file is just an extract of all the data. As you can see the columns increse from I to J in row 24. In the actual file this occurs in row 326198.

    I dont know if it makes a difference but in the actual data the number of columns occupied by values decreses
    Attached Files Attached Files

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Search columns and paste rows

    Public Sub FilterData()
    Dim rngArea As Range, xlCalc As XlCalculation
    On Error GoTo Handler
    With Application
        xlCalc = Application.Calculation
        .Calculation = xlCalculationManual
        .Application.ScreenUpdating = False
        .EnableEvents = False
    End With
    Sheets("sheet2").Columns(1).Clear
    Sheets("Sheet1").Select
    With Range(Cells(1, Columns.Count), Cells(Rows.Count, "A").End(xlUp).Offset(, Columns.Count - 1))
        .FormulaR1C1 = "=IF(RC2=4,1,""x"")"
        For Each rngArea In .SpecialCells(xlCellTypeFormulas, xlNumbers).Areas
            Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(rngArea.Rows.Count, 4).Value = rngArea.Offset(, 7 - Columns.Count).Resize(, 4).Value
        Next rngArea
        .Clear
    End With
    ExitPoint:
    With Application
        .Calculation = xlCalc
        .Application.ScreenUpdating = True
        .EnableEvents = True
    End With
    Exit Sub
    
    Handler:
    MsgBox "Error etc...", vbCritical, "Error"
    Resume ExitPoint
    
    End Sub
    Others may suggest Auto Filter... given the volume of data I don't know how feasible that is... I added in some Application events given that fact (re: calculation, screenupdating and events)

+ 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