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.
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
I hope I have been clear with my explanation. I know it's quite a mess...
Thanks!
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!