MeisterConrad
New Member
- Joined
- Jan 17, 2017
- Messages
- 42
- Office Version
- 2007
I have a Macro that add a bunch of worksheets, and creates a table, whose name is numbered using a counter on each of those sheets. I want to have the code input formulas into two columns of the table that refer to places in the table that was just created.
I tried using "Table" & n instead of "Table4", but that won't translate somehow. Should I replace all the instances of "Table4" with "lo" (the ListObject)? what would be the correct syntax? I need to have this name/reference dilemma solved in order for subsequent Sheets to be created correctly. What should I do?
VBA Code:
Dim c As Range
Dim n As Integer
Dim lo As ListObject
n = 3
For Each c In Sheets("Sheet1").Range("LedgerLocList")
Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
n = n + 1
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$D$10:$N$12"), , xlYes).Name = _Table" & n
Set lo = Range("Table" & n).ListObject
Input Formulae for Balance Columns
Range("M12").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(Table4[[#This Row],[Debits]]="""",Table4[[#This Row],[Credits]]=""""),"""",IF(Table4[[#This Row],[Debits]]<>"""",R[-1]C-Table4[[#This Row],[Debits]],R[-1]C+Table4[[#This Row],[Credits]]))"
Range("N12").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(Table4[[#This Row],[Credits]]="""",Table4[[#This Row],[Debits]]=""""),"""",IF(Table4[[#This Row],[Date Cleared]]="""",R[-1]C,IF(Table4[[#This Row],[Debits]]<>"""",R[-1]C-Table4[[#This Row],[Debits]],R[-1]C+Table4[[#This Row],[Credits]])))"
I tried using "Table" & n instead of "Table4", but that won't translate somehow. Should I replace all the instances of "Table4" with "lo" (the ListObject)? what would be the correct syntax? I need to have this name/reference dilemma solved in order for subsequent Sheets to be created correctly. What should I do?