and i am geting error code Run time error 13 Type Mismatch. Please help
Coding i use now to work in 2003 macro:-
Code: Select all
Function WorksheetExists(WorksheetName As String) As Boolean
Dim sht As Object
For Each sht In ActiveWorkbook.Sheets
If sht.Name = WorksheetName Then WorksheetExists = True: Exit For
Next sht
End Function
Sub BD_Adj_JV_1()
Application.DisplayAlerts = False
If WorksheetExists("Working") = True Then Sheets("Working").Delete
If WorksheetExists("159901") = True Then Sheets("159901").Delete
If WorksheetExists("JE") = True Then Sheets("JE").Delete
Sheets("base").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Dim myrange1 As Range
Set myrange1 = Sheets("base").Range("A1:H" & rn1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
myrange1).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion10
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("GL Amount"), "Sum of GL Amount", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of GL Amount")
.NumberFormat = "0.00_);(0.00)"
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GL Code")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #").Subtotals = Array _
(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveWorkbook.ShowPivotTableFieldList = False
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F12").Select
ActiveSheet.Name = "Working"
Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
Range("A1").Select
Selection.EntireRow.Delete
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = 2 To rn1 - 1
If Cells(r, "A").Value = "" Then Cells(r, "A").Value = Cells(r - 1, "A").Value
Next
Range("C1").Select
Selection.EntireColumn.Insert
Range("C1").Value = "Description"
For r = rn1 - 1 To 2 Step -1
If Cells(r, "D").Value = 0 Or Cells(r, "D").Value = -0 Then Rows(r).Delete
Next
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = 2 To rn1 - 1
Cells(r, "C").Value = "OARS Adj> " & Cells(r, "A").Value
Next
Range("A2:D" & rn1 - 1).Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("mapping").Select
rn2 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Dim myrange2 As Range
Set myrange2 = Sheets("mapping").Range("A2:F" & rn2)
Sheets("Working").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Columns("E:E").Select
Selection.NumberFormat = "@"
For r = 2 To rn1 - 1
vfind = Cells(r, "B").Value
On Error Resume Next
Cells(r, "E").Value = Application.WorksheetFunction.VLookup(vfind, myrange2, 5, False)
Cells(r, "F").Value = Application.WorksheetFunction.VLookup(vfind, myrange2, 6, False)
Next
Range("A" & rn1).Select
Selection.EntireRow.Delete
Range("E1").Value = "New Code"
Range("F1").Value = "Extension"
Cells.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.EntireColumn.AutoFit
Rows("1:1").Select
Selection.Font.Bold = True
End Sub
Sub BD_Adj_JV_2()
Sheets("Working").Select
Sheets("Working").Copy before:=Sheets(1)
Sheets("Working (2)").Select
Sheets("Working (2)").Name = "JE"
Sheets("base").Select
Sheets("base").Copy after:=Sheets(1)
Sheets("base (2)").Select
Sheets("base (2)").Name = "159901"
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = rn1 To 2 Step -1
If Cells(r, "F").Value = 159901 Then Cells(r, "I").Value = 1
Next
Range("A2:I" & rn1).Select
Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
start_row = 0
For r = 2 To rn1
If Cells(r, "I").Value <> 1 Then
start_row = r
Exit For
End If
Next
If start_row > 0 Then
Range("A" & start_row, "A" & rn1).Select
Selection.EntireRow.Delete
End If
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = 2 To rn1
Cells(r, "I").Value = Left(Cells(r, "C").Value & "/" & Cells(r, "B").Value, 30)
Cells(r, "J").Value = "24560101X901"
Cells(r, "K").Value = "000000200000C1000010000000"
Next
Columns("G:G").Select
Selection.Copy
Columns("J:J").Select
Selection.Insert Shift:=xlToRight
Sheets("JE").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = rn1 To 2 Step -1
If Cells(r, "B").Value = "159901" Then Rows(r).Delete
Next
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Sheets("159901").Select
rn2 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Range("I2:L" & rn2).Select
Selection.Copy
Sheets("JE").Select
Range("C" & rn1 + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Cells.Select
Selection.EntireColumn.AutoFit
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
stot = 0
sdesc = "OARS Adj>"
For r = 2 To rn1
If Cells(r, "B").Value = "105060" Then
stot = stot + Cells(r, "D").Value
If sdesc = "OARS Adj>" Then
sdesc = sdesc & " " & Cells(r, "A").Value
Else
sdesc = sdesc & " & " & Cells(r, "A").Value
End If
End If
Next
Sheets("105060").Select
Range("E1").Value = sdesc
Range("E2").Value = stot
Sheets("JE").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = rn1 To 2 Step -1
If Cells(r, "B").Value = "105060" Then Rows(r).Delete
Next
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Sheets("105060").Select
Range("B5:E15").Select
Selection.Copy
Sheets("JE").Select
Range("C" & rn1 + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("D:D").Select
Selection.NumberFormat = "0.00_);(0.00)"
Range("A1:B1").Select
Selection.EntireColumn.Delete
Range("A1:A3").Select
Selection.EntireRow.Insert
Range("A1").Select
Selection.EntireColumn.Insert
Range("B1").Value = "<< Pre-assigned JE number >>"
Range("B2").Value = "<< JE Description >>"
Range("C1").Value = " Session : "
Range("C2").Value = " Amount : "
Range("A2").Value = "OARS Adj> "
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Range("A4").Value = "Account"
Range("D" & rn1 + 1).Value = "12211001X060"
Range("E" & rn1 + 1).Value = "000000200000C1000010000000"
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For r = 5 To rn1
Cells(r, "A").Value = Cells(r, "D").Value & Cells(r, "E").Value
Next
Range("A1:D2").Select
Selection.Interior.ColorIndex = 15
Selection.Font.Bold = True
Cells.Select
Selection.EntireColumn.AutoFit
gtot = 0
For r = 5 To rn1 - 1
gtot = gtot + Cells(r, "C").Value
Next
Range("C" & rn1).Value = -gtot
Cells.Select
Selection.Font.Name = "Arial"
Selection.Font.Size = 9
For r = 5 To rn1
Cells(r, "C").Value = Application.WorksheetFunction.Round(Cells(r, "C").Value, 2)
Next
Range("A1").Select
End Sub