Hey MrExcel Community!
Long time browser here, you guys have basically taught me VBA 101(thanks!) but first post as I can't seem to find my specific problem in other threads. I'm an actuary, definitely not a coder, and am trying to make a simple button/program to keep a main 'Outstanding Trouble' tab updated with only transactions still marked as trouble in monthly tabs and remove when the trouble cell in the month's tab is unmarked. I already have the monthly tabs trouble columns corresponding to a boolean true/false column(P) and am trying to use those boolean values to copy/paste the range of the 'TRUE' rows(A thru O) into the main 'Outstanding Trouble' tab. I'm running into a runtime error "Subscript out of range" in my code, probably in my first For Each loop. Here's my code so far:
Option Explicit
Sub UpdateTrouble()
'maybe a command to clear entire Outstanding Trouble tab to avoid rewrites?
Dim Month As Worksheet
Dim rng As Range
Dim cell As Range
Dim srceRng As Range
Dim destRng As Range
'Begin the loop.
For Each Month In Worksheets
Set rng = Workbooks("WorkInProgress.xls").Sheets(ActiveSheet).Range("P2:P699")
'Pick out the "TRUE" trouble rows in each Month
For Each cell In rng
If cell.Value = "TRUE" Then
Set srceRng = Workbooks("WorkInProgress.xls").Sheets(ActiveSheet).Range("A" & ActiveCell.Row & ":O" & ActiveCell.Row)
'still need to set destRng to first available row in Sheet 1 instead of just A1
Set destRng = Workbooks("WorkInProgress.xls").Sheets("Outstanding Trouble").Range("A1")
srceRng.Copy
Workbooks("WorkInProgress.xls").Sheets("Outstanding Trouble").Paste destRng
Else: End If
Next
Next
End Sub
I'm sure it's an easy syntax patch but this is a slow learning process for me. Thanks a ton in advance for any help in the matter!
Long time browser here, you guys have basically taught me VBA 101(thanks!) but first post as I can't seem to find my specific problem in other threads. I'm an actuary, definitely not a coder, and am trying to make a simple button/program to keep a main 'Outstanding Trouble' tab updated with only transactions still marked as trouble in monthly tabs and remove when the trouble cell in the month's tab is unmarked. I already have the monthly tabs trouble columns corresponding to a boolean true/false column(P) and am trying to use those boolean values to copy/paste the range of the 'TRUE' rows(A thru O) into the main 'Outstanding Trouble' tab. I'm running into a runtime error "Subscript out of range" in my code, probably in my first For Each loop. Here's my code so far:
Option Explicit
Sub UpdateTrouble()
'maybe a command to clear entire Outstanding Trouble tab to avoid rewrites?
Dim Month As Worksheet
Dim rng As Range
Dim cell As Range
Dim srceRng As Range
Dim destRng As Range
'Begin the loop.
For Each Month In Worksheets
Set rng = Workbooks("WorkInProgress.xls").Sheets(ActiveSheet).Range("P2:P699")
'Pick out the "TRUE" trouble rows in each Month
For Each cell In rng
If cell.Value = "TRUE" Then
Set srceRng = Workbooks("WorkInProgress.xls").Sheets(ActiveSheet).Range("A" & ActiveCell.Row & ":O" & ActiveCell.Row)
'still need to set destRng to first available row in Sheet 1 instead of just A1
Set destRng = Workbooks("WorkInProgress.xls").Sheets("Outstanding Trouble").Range("A1")
srceRng.Copy
Workbooks("WorkInProgress.xls").Sheets("Outstanding Trouble").Paste destRng
Else: End If
Next
Next
End Sub
I'm sure it's an easy syntax patch but this is a slow learning process for me. Thanks a ton in advance for any help in the matter!