+ Reply to Thread
Results 1 to 7 of 7

Code to loop through input sheet and whenever a cell matches copy to a new sheet

Hybrid View

  1. #1
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Code to loop through input sheet and whenever a cell matches copy to a new sheet

    say I want code OK1 & OK2 information to be pulled from the input tab.
    One way...
    Sub J3v16()
    Dim Data, Code, Temp, i As Long, ii As Long, x As Long
    Data = Sheets("Input").Cells(1).CurrentRegion: Code = Array("OK1", "OK2")
    ReDim Temp(1 To UBound(Data) * UBound(Data), 1 To 3)
    For i = LBound(Code) To UBound(Code)
        x = IIf(i = 0, x + 1, x + 2)
        Temp(x, 1) = "Code": Temp(x, 2) = Code(i)
        x = x + 1: Temp(x, 2) = "Ticker": Temp(x, 3) = "Type"
        For ii = 2 To UBound(Data)
            If Data(ii, 7) = Code(i) Then
                x = x + 1: Temp(x, 2) = Data(ii, 1): Temp(x, 3) = Data(ii, 10)
            End If
        Next ii
    Next i
    Sheet2.Range("A" & Rows.Count).End(xlUp).Resize(x, 3).Value = Temp
    End Sub
    Last edited by Sintek; 06-18-2021 at 11:17 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  2. #2
    Registered User
    Join Date
    07-08-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Code to loop through input sheet and whenever a cell matches copy to a new sheet

    But it crashes for 50K lines saying out of memory at the ReDim temp (1 to Ubound(Data) * UBound(Data), 1 to 3) line. Any thoughts how to fix this?
    Last edited by wolfdemon; 06-18-2021 at 12:57 PM.

+ 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. excel loop to copy data from sheet 1 to sheet 2 based on matches
    By vpan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2021, 07:46 PM
  2. code to copy paste the rows to a new sheet if matches 2 categories
    By Elainefish in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2018, 01:45 AM
  3. Replies: 6
    Last Post: 05-29-2017, 04:16 PM
  4. [SOLVED] Vba code to copy unique email id data from input sheet to output sheet
    By UPA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2017, 07:19 AM
  5. [SOLVED] Copy cell range from “input sheet” to “output sheet”
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2014, 01:57 PM
  6. Pull data from a specific sheet that matches cell value on Input Sheet
    By vaciaravino in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-12-2012, 08:38 PM
  7. Replies: 1
    Last Post: 10-30-2009, 10:58 AM

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