Apply Macro to another sheet in the same workbook

link57

New Member
Joined
Mar 10, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi all ! I'm new to VBA and would like to know how to apply Macro to another sheet in the same workbook. I have created some macro buttons like below for one department (a) to input data:

1615362895541.png


Now I want to create another sheet for another department (b) to input data, with the same macro buttons as the sheet of department (a). Please help.

Thank you
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi
In you macro you can use
VBA Code:
With Activesheet
.
.
. 
End With
It would be better to share your code/s
 
Upvote 0
Please find the sample in here. I would like to have the same macro buttons with the same function for licensing & accounting sheets. It would be great if there are some improvement advices.


Thank you
 
Upvote 0
VBA Code:
Private Sub btnInsert_Click()
    Dim dong_cuoi As Long
    dong_cuoi = Sheet1.Range("B10000").End(xlUp).Row + 1
    With ActiveSheet
         .Range("B" & dong_cuoi) = txtSTT.Text
         .Range("C" & dong_cuoi) = txtClientcode.Text
         .Range("D" & dong_cuoi) = txtClientname.Text
         .Range("E" & dong_cuoi) = txtProposal.Text
         .Range("F" & dong_cuoi) = txtContract.Text
         .Range("G" & dong_cuoi) = txtServicestatus.Text
         .Range("H" & dong_cuoi) = txtADate.Text
         .Range("I" & dong_cuoi) = txtServicemonth.Text
         .Range("J" & dong_cuoi) = txtServiceyear.Text
         .Range("K" & dong_cuoi) = txtBillable.Text
         .Range("L" & dong_cuoi) = txtVAT.Text
         .Range("M" & dong_cuoi) = txtTotalUSD.Text
         .Range("N" & dong_cuoi) = txtTotalVND.Text
         .Range("O" & dong_cuoi) = txtPaymentstat.Text
         .Range("P" & dong_cuoi) = txtPIC.Text
    End With
End Sub

VBA Code:
Sub Macro_print()
'
' Macro_print Macro
'

'
    ActiveWindow.ActiveSheet.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub

VBA Code:
Sub Macro1_sortmonth()
'
' Macro1_sortmonth Macro
'

'
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add Key _
        :=Range("I9"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveSheet.AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub


 
Upvote 0
Solution
You are welcome
And thank you for the feedback
Be happy & safe
 
Upvote 0

Forum statistics

Threads
1,215,254
Messages
6,123,893
Members
449,132
Latest member
Rosie14

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