I have the following code which works fine if I move through it with F8. However, I get the following error if I just run the macro:
Error Number: 1004
Error Description: Select method of range class failed
Here is the section of code which calls two different functions
they call (Case 10 calls both case 11 only calls the first one):
both above functions call the following:
any idea why it breaks when running macro but works fine when I F8 through the code?
thanks in advance
Error Number: 1004
Error Description: Select method of range class failed
Here is the section of code which calls two different functions
Code:
Case 10
intCELL = cell.Row
strGL = "{610000,619000,619900,631000,632000,633000,634000,640000," _
& "650000,660000,661000,671000,672000,673000,679000,680000," _
& "685000,690000,721000,721100,721200,728000,729000,730000," _
& "760000}"
strSUS300 = "{" & DYTB300(wsOB, intCELL, wbRECON) & "}"
strSUS400 = "{" & DYTB400(wsOB, intCELL, wbRECON) & "}"
intCOL = 4
Do Until intCOL >= 13
Set rng = ws.Cells(cell.Row, intCOL)
Select Case intCOL
Case 4
rng.FormulaR1C1 = "=sum(SUM(SUMIFS('Trail Balance(s)'!R" _
& intROWtb & "C" & intCOLTBamt & ":R" & lngROWtb _
& "C" & intCOLTBamt & ",'Trail Balance(s)'!R" _
& intROWtb & "C" & intCOLTBgl & ":R" & lngROWtb _
& "C" & intCOLTBgl & "," & strGL _
& ",'Trail Balance(s)'!R" & intROWtb & "C" _
& intCOLTBsus & ":R" & lngROWtb & "C" & intCOLTBsus _
& "," & strSUS400 & "))-SUM(SUMIFS('Trail Balance(s)'!R" _
& intROWtb & "C" & intCOLTBamt & ":R" & lngROWtb _
& "C" & intCOLTBamt & ",'Trail Balance(s)'!R" _
& intROWtb & "C" & intCOLTBgl & ":R" & lngROWtb _
& "C" & intCOLTBgl & "," & strGL _
& ",'Trail Balance(s)'!R" & intROWtb & "C" _
& intCOLTBsus & ":R" & lngROWtb & "C" & intCOLTBsus _
& "," & strSUS300 & ")))"
Case 6
rng.FormulaR1C1 = "=sum(SUM(SUMIFS('OBIEE'!R" _
& intROWob & "C" & intCOLOBamt & ":R" & lngROWob _
& "C" & intCOLOBamt & ",'OBIEE'!R" _
& intROWob & "C" & intCOLOBgl & ":R" & lngROWob _
& "C" & intCOLOBgl & "," & strGL _
& ",'OBIEE'!R" & intROWob & "C" _
& intCOLOBsus & ":R" & lngROWob & "C" & intCOLOBsus _
& "," & strSUS400 & "))-SUM(SUMIFS('OBIEE'!R" _
& intROWob & "C" & intCOLOBamt & ":R" & lngROWob _
& "C" & intCOLOBamt & ",'OBIEE'!R" _
& intROWob & "C" & intCOLOBgl & ":R" & lngROWob _
& "C" & intCOLOBgl & "," & strGL _
& ",'OBIEE'!R" & intROWob & "C" _
& intCOLOBsus & ":R" & lngROWob & "C" & intCOLOBsus _
& "," & strSUS300 & ")))"
Case 8
rng.FormulaR1C1 = "=RC[-4]-RC[-2]"
Case 10
rng.Value = 0#
With rng.Interior
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.599993896298105
End With
Case 12
rng.FormulaR1C1 = "=RC[-6]-RC[-2]"
End Select
intCOL = intCOL + 2
Loop
Case 11
intCELL = cell.Row
strGL = "{610000,619000,619900,631000,632000,633000,634000,640000," _
& "650000,660000,661000,671000,672000,673000,679000,680000," _
& "685000,690000,721000,721100,721200,728000,729000,730000," _
& "760000}"
strSUS300 = "{" & DYTB300(wsOB, intCELL, wbRECON) & "}"
intCOL = 4
Do Until intCOL >= 13
Set rng = ws.Cells(cell.Row, intCOL)
Select Case intCOL
Case 4
rng.FormulaR1C1 = "=SUM(SUMIFS('Trail Balance(s)'!R" _
& intROWtb & "C" & intCOLTBamt & ":R" & lngROWtb _
& "C" & intCOLTBamt & ",'Trail Balance(s)'!R" _
& intROWtb & "C" & intCOLTBgl & ":R" & lngROWtb _
& "C" & intCOLTBgl & "," & strGL _
& ",'Trail Balance(s)'!R" & intROWtb & "C" _
& intCOLTBsus & ":R" & lngROWtb & "C" & intCOLTBsus _
& "," & strSUS300 & "))"
Case 6
rng.FormulaR1C1 = "=SUM(SUMIFS('OBIEE'!R" _
& intROWob & "C" & intCOLOBamt & ":R" & lngROWob _
& "C" & intCOLOBamt & ",'OBIEE'!R" _
& intROWob & "C" & intCOLOBgl & ":R" & lngROWob _
& "C" & intCOLOBgl & "," & strGL _
& ",'OBIEE'!R" & intROWob & "C" _
& intCOLOBsus & ":R" & lngROWob & "C" & intCOLOBsus _
& "," & strSUS300 & "))"
Case 8
rng.FormulaR1C1 = "=RC[-4]-RC[-2]"
Case 10
rng.Value = 0#
With rng.Interior
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.599993896298105
End With
Case 12
rng.FormulaR1C1 = "=RC[-6]-RC[-2]"
End Select
intCOL = intCOL + 2
Loop
they call (Case 10 calls both case 11 only calls the first one):
Code:
Function DYTB300(wsOB As Worksheet, intCELL As Integer, wbRECON As Workbook)
Dim lngROW As Long, lngCOL As Long
Dim intROWst As Integer, intACCT As Integer, intGL As Integer, intSUS As Integer
Dim rngHEAD As Range, rngCOPY As Range, rng As Range
Dim strSUS As String
Dim wb As Workbook
Dim wsDY As Worksheet
Set wsDY = wbRECON.Worksheets.Add(after:=wbRECON.Worksheets(Worksheets.Count))
With wsOB
lngROW = LASTrow(wsOB)
lngCOL = LASTCOL(wsOB)
intROWst = wsOB.Cells(1, 1).End(xlDown).Row
Set rngHEAD = wsOB.Range(wsOB.Cells(intROWst, 1), wsOB.Cells(intROWst, lngCOL))
intACCT = rngHEAD.Find("SBS_CD").Column
intGL = rngHEAD.Find("SGL_CD").Column
intSUS = rngHEAD.Find("SUS_ID").Column
Set rngCOPY = wsOB.Range(wsOB.Cells(intROWst, intACCT), wsOB.Cells(lngROW, intACCT))
rngCOPY.Copy
wsDY.Cells(1, 1).PasteSpecial xlPasteAll
Set rngCOPY = wsOB.Range(wsOB.Cells(intROWst, intGL), wsOB.Cells(lngROW, intGL))
rngCOPY.Copy
wsDY.Cells(1, 2).PasteSpecial xlPasteAll
Set rngCOPY = wsOB.Range(wsOB.Cells(intROWst, intSUS), wsOB.Cells(lngROW, intSUS))
rngCOPY.Copy
wsDY.Cells(1, 3).PasteSpecial xlPasteAll
End With
wsDY.Select
With wsDY
lngROW = LASTrow(wsDY)
lngCOL = LASTCOL(wsDY)
Set rng = wsDY.Range(wsDY.Cells(1, 1), wsDY.Cells(lngROW, lngCOL))
appEXCEL.CutCopyMode = False
rng.AutoFilter
rng.AutoFilter Field:=2, Criteria1:=Array( _
"610000", "619000", "619900", "631000", "632000", "633000", "634000", "640000", _
"650000", "660000", "661000", "671000", "672000", "673000", "679000", "680000", _
"685000", "690000", "721000", "721100", "721200", "728000", "729000", "730000", _
"760000"), Operator:=xlFilterValues
rng.SpecialCells(xlCellTypeVisible).Copy
wsDY.Cells(1, 5).PasteSpecial xlPasteAll
wsDY.AutoFilterMode = False
wsDY.Columns("A:D").EntireColumn.Delete
Set rngHEAD = wsDY.Range(wsDY.Cells(1, 1), wsDY.Cells(1, lngCOL))
Set rngCOPY = wsDY.Range(wsDY.Cells(1, 2), wsDY.Cells(lngROW, lngCOL))
intACCT = rngHEAD.Find("SBS_CD").Column
intGL = rngHEAD.Find("SGL_CD").Column
intSUS = rngHEAD.Find("SUS_ID").Column
rngHEAD.AutoFilter Field:=1, Criteria1:="300"
rngCOPY.SpecialCells(xlCellTypeVisible).Copy
wsDY.Cells(1, 7).PasteSpecial xlPasteAll
wsDY.AutoFilterMode = False
wsDY.Columns("A:F").EntireColumn.Delete
Set rng = wsDY.Range(wsDY.Cells(1, 1), wsDY.Cells(lngROW, 2))
rng.Sort Key1:=wsDY.Range("A2:A" & lngROW), Order1:=xlAscending, _
Key2:=wsDY.Range("B2:B" & lngROW), Order2:=xlAscending, Header:=xlYes
rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
lngROW = LASTrow(wsDY)
Set rng = wsDY.Range(wsDY.Cells(2, 2), wsDY.Cells(lngROW, 2))
strSUS = Combine(rng)
End With
wsDY.Delete
DYTB300 = strSUS
End Function
Function DYTB400(wsOB As Worksheet, intCELL As Integer, wbRECON As Workbook)
Dim lngROW As Long, lngCOL As Long
Dim intROWst As Integer, intACCT As Integer, intGL As Integer, intSUS As Integer
Dim rngHEAD As Range, rngCOPY As Range, rng As Range
Dim strSUS As String
Dim wb As Workbook
Dim wsDY As Worksheet
Set wsDY = wbRECON.Worksheets.Add(after:=wbRECON.Worksheets(Worksheets.Count))
With wsOB
lngROW = LASTrow(wsOB)
lngCOL = LASTCOL(wsOB)
intROWst = wsOB.Cells(1, 1).End(xlDown).Row
Set rngHEAD = wsOB.Range(wsOB.Cells(intROWst, 1), wsOB.Cells(intROWst, lngCOL))
intACCT = rngHEAD.Find("SBS_CD").Column
intGL = rngHEAD.Find("SGL_CD").Column
intSUS = rngHEAD.Find("SUS_ID").Column
Set rngCOPY = wsOB.Range(wsOB.Cells(intROWst, intACCT), wsOB.Cells(lngROW, intACCT))
rngCOPY.Copy
wsDY.Cells(1, 1).PasteSpecial xlPasteAll
Set rngCOPY = wsOB.Range(wsOB.Cells(intROWst, intGL), wsOB.Cells(lngROW, intGL))
rngCOPY.Copy
wsDY.Cells(1, 2).PasteSpecial xlPasteAll
Set rngCOPY = wsOB.Range(wsOB.Cells(intROWst, intSUS), wsOB.Cells(lngROW, intSUS))
rngCOPY.Copy
wsDY.Cells(1, 3).PasteSpecial xlPasteAll
End With
wsDY.Select
With wsDY
lngROW = LASTrow(wsDY)
lngCOL = LASTCOL(wsDY)
Set rng = wsDY.Range(wsDY.Cells(1, 1), wsDY.Cells(lngROW, lngCOL))
appEXCEL.CutCopyMode = False
rng.AutoFilter
rng.AutoFilter Field:=2, Criteria1:=Array( _
"610000", "619000", "619900", "631000", "632000", "633000", "634000", "640000", _
"650000", "660000", "661000", "671000", "672000", "673000", "679000", "680000", _
"685000", "690000", "721000", "721100", "721200", "728000", "729000", "730000", _
"760000"), Operator:=xlFilterValues
rng.SpecialCells(xlCellTypeVisible).Copy
wsDY.Cells(1, 5).PasteSpecial xlPasteAll
wsDY.AutoFilterMode = False
wsDY.Columns("A:D").EntireColumn.Delete
Set rngHEAD = wsDY.Range(wsDY.Cells(1, 1), wsDY.Cells(1, lngCOL))
Set rngCOPY = wsDY.Range(wsDY.Cells(1, 2), wsDY.Cells(lngROW, lngCOL))
intACCT = rngHEAD.Find("SBS_CD").Column
intGL = rngHEAD.Find("SGL_CD").Column
intSUS = rngHEAD.Find("SUS_ID").Column
rngHEAD.AutoFilter Field:=1, Criteria1:="400"
rngCOPY.SpecialCells(xlCellTypeVisible).Copy
wsDY.Cells(1, 10).PasteSpecial xlPasteAll
wsDY.AutoFilterMode = False
wsDY.Columns("A:I").EntireColumn.Delete
Set rng = wsDY.Range(wsDY.Cells(1, 1), wsDY.Cells(lngROW, 2))
rng.Select
rng.Sort Key1:=wsDY.Range("A2:A" & lngROW), Order1:=xlAscending, _
Key2:=wsDY.Range("B2:B" & lngROW), Order2:=xlAscending, Header:=xlYes
rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
lngROW = LASTrow(wsDY)
Set rng = wsDY.Range(wsDY.Cells(2, 2), wsDY.Cells(lngROW, 2))
strSUS = Combine(rng)
End With
wsDY.Delete
DYTB400 = strSUS
End Function
both above functions call the following:
Code:
Function Combine(WorkRng As Range, Optional Sign As String = ";") As String
Dim rng As Range
Dim OutStr As String
For Each rng In WorkRng
If rng.Text <> "," Then
OutStr = OutStr & rng.Text & Sign
End If
Next
Combine = Left(OutStr, Len(OutStr) - 1)
End Function
any idea why it breaks when running macro but works fine when I F8 through the code?
thanks in advance