Buttons that copy a filtered row into another sheet

Albert_R

New Member
Joined
Jan 23, 2017
Messages
1
Hi,

I'm rather new to Excel VBA, but I manage to make it work with the help of the recorder and the help of this forum and others like this one. So, thanks for all the work!

I have a database with a lot of information on people. Each person has an employee number assigned, so I've used this as a base for my code.

In the sheet "EMAIL BAJAS", I have a list of names with the number. This part creates a Button when the necessary conditions are met, and I gave each button a name which is the same as the employee number.

I think this part works well, I'm just posting it just in case there is something wrong. This code is placed inside the Worksheet, not in a separate Module.

Code:
Private Sub Worksheet_Calculate()
    Call CopyMacro
End Sub

Public Sub CopyMacro()
Sheets("EMAIL BAJAS").Buttons.Delete
Dim i As Integer
For i = 2 To 30
    If Cells(i, 7) = True Then
        Dim btn As Button
        Application.ScreenUpdating = False
        Dim t As Range
        Set t = Sheets("EMAIL BAJAS").Range(Cells(i, 8), Cells(i, 8))
        Set btn = Sheets("EMAIL BAJAS").Buttons.Add(t.Left, t.Top, t.Width, t.Height)
        With btn
            .OnAction = "CopyButton"
            .Caption = "Copy to upload"
            .Name = Cells(i, 1)
        End With
   End If
      
   Next
    
  Application.ScreenUpdating = True

End Sub

Now I have several buttons when the condition is met. What I now want is that each button calls another macro. This macro would use the button name (as Application.Caller) as a value to filter for in the main database. This part works, but I can't manage to do the rest. What I now want is to copy a certain range of values from the filter, all rows starting from column C and avoiding the header. Then I want to insert this data in a new sheet, but in a way that it doesn't overwrite previous data. The filter works okay, but I can't manage to copy the information.

This code is in Module1

Code:
Sub CopyButton()

Dim buttonnum As Integer
buttonnum = Application.Caller

Sheets("Master list_all").Select
ActiveSheet.Range("$A$1:$AJ$2623").AutoFilter Field:=4, Criteria1:=buttonnum
ActiveSheet.AutoFilter.Range.Offset(1, 2).Copy

'I THINK THE ISSUE IS SOMETHING IN HERE

Sheets("UPLOAD").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False

MsgBox ("Copied number " & buttonnum)

End Sub

I hope I have been clear with my explanation. I know it's quite a mess...

Thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,216,086
Messages
6,128,734
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top