Hi i have some code which extracts the expenses from a list of combined income and expenses. It runs great if I manually select the correct sheet ("INCOMEXPENSESa") first. If I dont select the right sheet it creats havoc on the active sheet Im sure this should be simple but I cant seem to get the right sintax to select the sheet in the macro. Thank you if anyone can help me with this.
Code:
Sub ExtractExpensesc()
'This is macro 3 Select sheet INCOMEXPENSESa first
Dim twb As Workbook
Dim rng As Range
Dim ar As Variant
Dim mysheet As Worksheet
Dim Name As String
Dim Sheet As Worksheet
Set twb = ThisWorkbook
Set rng = Range("A2:E2")
ar = Array("Payment", "Name1", "Name2", "Amount", "Date")
rng = ar
rng.Borders(xlEdgeRight).LineStyle = xlContinuous
rng.Borders(xlEdgeLeft).LineStyle = xlContinuous
rng.Borders(xlEdgeTop).LineStyle = xlContinuous
rng.Borders(xlEdgeBottom).LineStyle = xlContinuous
rng.Borders(xlInsideVertical).LineStyle = xlContinuous
Range("A3", Range("E65536").End(xlUp)).Sort [d3], 1
Range("D2", Range("E65536").End(xlUp)).AutoFilter 1, "<0"
Range("A2", Range("E65536").End(xlUp)).Copy
Set mysheet = Sheets.Add
On Error Resume Next
mysheet.Name = "ExtractedExpensesc"
ActiveWorkbook.Sheets("ExtractedExpensesc").Tab.ColorIndex = 6
[a2].PasteSpecial
[A1] = -1
[A1].Copy
Range("D3", Range("D65536").End(xlUp)).PasteSpecial , 4
Range("D3", Range("D65536").End(xlUp)).Style = "Currency"
Columns("A:E").AutoFit
Range("A3", Range("E65536").End(xlUp)).Sort [b3], 1
twb.Sheets("INCOMEXPENSESa").[d2].AutoFilter
[A1].Select
End Sub