CollegeExcel
New Member
- Joined
- Mar 11, 2022
- Messages
- 4
- Office Version
- 365
- 2021
- Platform
- Windows
Hi all,
As the title mentions.
I build a VBA macro which filters data based on Month, and copy/paste it into a new sheet. However every time I run this code, it jumps to the page where it should paste. It just tiring to click back on the main sheet every time.
Wondering what function I can use to disable that? Would appreciate any ideas.
Here is a snippet:
Code:
As the title mentions.
I build a VBA macro which filters data based on Month, and copy/paste it into a new sheet. However every time I run this code, it jumps to the page where it should paste. It just tiring to click back on the main sheet every time.
Wondering what function I can use to disable that? Would appreciate any ideas.
Here is a snippet:
Code:
Code:
Sub copy_data_2_new_sheets()
Dim count_col As Long
Dim count_row As Long
Dim reg As String
Dim check As Long
check = 0
reg = Sheet1.Cells(2, 9).Text
On Error GoTo oops
Sheets.Add(After:=Sheets(Sheets.Count)).Name = reg
check = 1
oops:
If check = 0 Then
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = False
End If
Sheets(reg).Cells.ClearContents
Sheet1.Activate
count_col = WorksheetFunction.CountA(Range("A4", Range("A4").End(xlToRight)))
count_row = WorksheetFunction.CountA(Range("A4", Range("A4").End(xlDown)))
ActiveSheet.Range("A4").AutoFilter Field:=2, Criteria1:=reg
Sheet1.Range(Cells(4, 1), Cells(count_row, count_col)). _
SpecialCells(xlCellTypeVisible).Copy
Sheets(reg).Cells(1, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheet1.ShowAllData
Sheet1.AutoFilterMode = False
Sheets(reg).Activate
Cells.Select
Cells.EntireColumn.AutoFit
Range("A2").Select
End Sub