+ Reply to Thread
Results 1 to 7 of 7

Find, copy and paste specific values.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Find, copy and paste specific values.

    Hey there,
    I'm trying to pull out some data from sheet with 40,000~ rows and about 300 employees.
    example.jpg
    I need to find values >0, sort it descending (by days) and exclude few JobNames. I tried to do that with aggregate and index formulas, but it's kind of slow on weaker PCs and I'm stuck now.
    So, what I need to do is this:
    1. Find Employee from P1 cell
    2. Copy Job, Days, Sum, Average (these columns are not next to each other)
    3. Exclude few specified JobNames in R1:R2 range
    4. Paste it sorted descending by Days
    Ideally it would work on combobox change.
    Perhaps there is a better and faster way to achieve that? Any help is greatly appreciated! Thank you.
    Attached Files Attached Files
    Last edited by Pojzon; 10-14-2018 at 12:00 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,659

    Re: Find, copy and paste specific values.

    See if this is fast enough.
    For the layout for output range in uploaded workbook.
    Sub test()
        Dim a, x, i As Long, ii As Long, n As Long, myCol, Emp As String, flg As Boolean
        myCol = Array(2, 6, 7, 8): Emp = Sheets("sheet1").ComboBox1.Value
        x = Filter([transpose(if(r1:r10000<>"",r1:r10000))], False, 0)
        a = Cells(1).CurrentRegion.Value
        For i = 2 To UBound(a, 1)
            If (a(i, 1) = Emp) * (a(i, 7) > 0) Then
                For ii = 0 To UBound(x)
                    If a(i, 2) = x(ii) Then flg = True: Exit For
                Next
                If Not flg Then
                    n = n + 1
                    For ii = 0 To UBound(myCol)
                        a(n, ii + 1) = a(i, myCol(ii))
                    Next
                End If
                flg = False
            End If
        Next
        Range("k23").CurrentRegion.Offset(2).ClearContents
        If n > 0 Then
            With Range("k24").Resize(n, UBound(myCol) + 1)
                .Value = a
                .Sort .Cells(1, 2), 2, , .Cells(1, 3), 2
            End With
        Else
            MsgBox "No match"
        End If
    End Sub

  3. #3
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Find, copy and paste specific values.

    Thank you for reply, I will have to check it at work for final verdict, but so far it looks amazing and much faster than formulas. I have one more question. As I understant, adding "Call test" at Sub ComboBox1_Change() is the way to go? Is there any way to stop this macro from running whenever I write text to find instead of selecting it from drop down list? With formulas I just used:
    ComboBox1_GotFocus() Application.Calculation = xlManual
    ComboBox1_LostFocus() Application.Calculation = xlAutomatic
    which won't work in this situation.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,659

    Re: Find, copy and paste specific values.

    Follow the step.
    1) ThisWorkbook code Module
    Private Sub Workbook_Open()
        If ActiveSheet Is Sheets("Sheet1") Then Run Sheets("sheet1").CodeName & ".worksheet_activate"
    End Sub
    2) Sheet1 sheet code module
    Option Explicit
    
    Private Sub ComboBox1_Change()
        Range("k23").CurrentRegion.Offset(2).ClearContents
        If Me.ComboBox1.ListIndex = -1 Then Exit Sub
        Application.ScreenUpdating = False
        test
        Application.ScreenUpdating = True
    End Sub
    
    Private Sub Worksheet_Activate()
        Dim a, e
        a = Cells(1).CurrentRegion.Columns(1).Offset(1).Value
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For Each e In a
                If e <> "" Then .Item(e) = Empty
            Next
            Me.ComboBox1.List = .keys
        End With
    End Sub
    See attached
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Find, copy and paste specific values.

    I tried this and It still runs macro every time I type a letter in combobox, without letting me to finish full string that I'm looking for e.g. I'm looking for "ABC", but it runs macro when it found "A" employee, then when it found "AB" employee and then finally "ABC". Anyway It's not a big deal, I can live with that. Nonetheless you've done amazing job and I thank you for that!
    Last edited by Pojzon; 10-14-2018 at 12:03 PM.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Find, copy and paste specific values.

    Try adding this code to worksheet module
    Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
        If KeyCode = 13 Then
            Range("K23").CurrentRegion.Offset(2).ClearContents
            Application.ScreenUpdating = False
                Test
            Application.ScreenUpdating = True
        End If
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,659

    Re: Find, copy and paste specific values.

    Just change the event to Click
    Private Sub ComboBox1_Change()
    to
    Private Sub ComboBox1_Click

+ 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. Copy and paste only specific values to the row that contains the value
    By Helensa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2018, 12:48 PM
  2. [SOLVED] Find specific text within workbook's name, copy and paste it to specific cell
    By axtryo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2017, 02:57 AM
  3. Find specific Data copy and paste into Cell Macro VBA
    By kunmateo93 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2014, 10:17 AM
  4. Replies: 2
    Last Post: 03-05-2013, 07:52 AM
  5. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  6. Find the specific text and copy and paste in another cell only if true.
    By SHARIB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2012, 03:14 AM
  7. Excel: Find All (specific) Copy All, Paste All ?
    By coffee_king in forum Excel General
    Replies: 1
    Last Post: 09-19-2012, 02:15 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