Hello,
I'm trying to find a way to pull the value of an item in my VBA code to get stored each time a loop runs if certain conditions are met.
I have established that ShiftTime = "" at the beginning of the loop and then a value is calculated at the end of the loop, before moving on to the next set of data and getting cleared again.
I would like to know how I can have my code take that value each time the loop runs and put the value into another sheet or workbook. Everything I've found in my research points to taking existing data (already in an Excel sheet) and writing a code to copy and paste some values to a new sheet.
Any help is tremendously appreciated by this new user!
Below is a filtered-down version of my macro:
I'm trying to find a way to pull the value of an item in my VBA code to get stored each time a loop runs if certain conditions are met.
I have established that ShiftTime = "" at the beginning of the loop and then a value is calculated at the end of the loop, before moving on to the next set of data and getting cleared again.
I would like to know how I can have my code take that value each time the loop runs and put the value into another sheet or workbook. Everything I've found in my research points to taking existing data (already in an Excel sheet) and writing a code to copy and paste some values to a new sheet.
Any help is tremendously appreciated by this new user!
Below is a filtered-down version of my macro:
Sub Analysis()
Dim SessionRng As Range, Dn As Range, n As Long 'Declaring ranges
Set SessionRng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)) 'Assigning range values
With CreateObject("scripting.dictionary") 'Creating a dictionary for the array
.CompareMode = vbTextCompare 'Defining Compar Mode as text compare in the range
For Each Dn In SessionRng 'This first loop will create a unique range relating to each unique value in column A
If Not .Exists(Dn.Value) Then 'If the value of the cell doesn't exist in the dictionary yet...
.Add Dn.Value, Dn 'Create a new entry with the value of the active cell
Else 'If it does exist...
Set .Item(Dn.Value) = Union(.Item(Dn.Value), Dn) 'Add this row to the entry already in the array
End If
Next
'Declaring k as key entries and p as rows
Dim k As Variant, p As Variant
'I declare a bunch of variants here
'This loops through each session
For Each k In .keys
'I name a bunch of items here included ShiftTime, IGTime, and SFPTime
'This loops through each row within each session
For Each p In .Item(k)
'I have a bunch of conditional statements here that run on each row in the session
'Values are assigned to the items I created, including IGTime and SFPTime, but are all cleared at the start of the next session
'Values are assigned to the items I created, including IGTime and SFPTime, but are all cleared at the start of the next session
Next p ' Next row
'There's a bunch of math done down here, including finding ShiftTime if the conditions for SFPTime and IGTime are met in that session.
If SFPTime <> "" And IGTime <> "" Then
ShiftTime = SFPTime - IGTime
End If
Next k ' Next Session
End With
End Sub