I am getting an error when i input this code into my macro, with the error message stating that its an object defined error. Can i know where the error is coming from?
Option Explicit
Public Const strSA As String = "C:\Users\kentan\Desktop\Managed Fund "
Sub iris()
Dim i As Long
With ActiveSheet
With .Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 1))
.Sort key1:=.Columns(1), order1:=xlAscending , _
key2:=.Columns(2), order2:=xlAscending , _
Header:=xlYes, MatchCase:=False, _
Orientation:=xlTopToBottom, SortMethod:=xlStroke
End With
For i = 2 To .Rows.Count
If LCase(.Cells(i, "A").Value2) = LCase(.Cells(i - 1, "A").Value2) And _
LCase(.Cells(i, "A").Value2) <> LCase(.Cells(i + 1, "A").Value2) Then
newiris .Cells(i, "A").Value2, .Cells(i, "B").Value2
End If
Next i
End With
End Sub
Sub newiris(nm As String, nfo As String)
Application.DisplayAlerts = false
With Workbooks.Add
Do While .Worksheets.Count > 1: .Worksheets(2).Delete: Loop
.Worksheets(1).Cells(1, "A").Resize(1, 2) = Array(nm, nfo)
.SaveAs filename:=strSA & nm, FileFormat:=xlOpenXMLWorkbook
.Close savechanges:=False
End With
Application.DisplayAlerts = true
End Sub
.SaveAsand.Closewould directly interact with the newly added workbook fromWorkbooks.Addin the with statement. Technically it is the same as usingSet wb = Workbooks.Addand usingWith wbafterwards.Withblocks can hold an object reference and avoid needing to declare a local variable for it - I useWith New Somethingall the time =)