jocker_boy
Board Regular
- Joined
- Feb 5, 2015
- Messages
- 83
Hello,
I'm trying to run the code in last column.
Part of the code is perfect. Until this line it works good: Range(Cells(6, lc), Cells(lr, lc)).FormulaR1C1 = "=R[0]C[-1]*" & Application.ConvertFormula("$J6", xlA1, xlR1C1)
Then in second part of the code i would like to replace the range "EE" with "lc" variable. But i don't know how.
Thanks for the help.
Gonçalo
I'm trying to run the code in last column.
Part of the code is perfect. Until this line it works good: Range(Cells(6, lc), Cells(lr, lc)).FormulaR1C1 = "=R[0]C[-1]*" & Application.ConvertFormula("$J6", xlA1, xlR1C1)
Then in second part of the code i would like to replace the range "EE" with "lc" variable. But i don't know how.
Thanks for the help.
Gonçalo
VBA Code:
Sub test()
'Populate Auxiliar Columns
Dim lr As Long
Dim lc As Long
'Group Columns
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=8
' Find last row in column C with data
lr = Cells(Rows.Count, "C").End(xlUp).row
' Find last column in row 5 with data
lc = Cells(5, columns.Count).End(xlToLeft).Column
'Ungroup Columns
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
Range(Cells(6, lc + 3), Cells(6, lc + 3)).Select
Range(Cells(6, lc), Cells(lr, lc)).FormulaR1C1 = "=R[0]C[-1]*" & Application.ConvertFormula("$J6", xlA1, xlR1C1)
Dim r As Long, r2 As Long, last_row As Long
Dim next_row As Long, current_len As Long, test_len As Long
Dim Rng As String
With ActiveSheet
last_row = .Cells(Rows.Count, 1).End(xlUp).row
For r = 6 To lr
next_row = r + 1
If .Range("B" & next_row) > .Range("B" & r) Then
current_len = .Range("B" & r)
'create range
For r2 = r + 1 To last_row
test_len = .Range("B" & r2)
If current_len >= test_len Then
Rng = "EE" & r + 1 & ":" & "EE" & r2 - 1
Exit For
End If
Next
.Range("EE" & r).Formula = "=SUBTOTAL(9," & Rng & ")"
End If
Next
End With
End Sub