I3atnumb3rs
New Member
- Joined
- Nov 2, 2018
- Messages
- 34
Hello! I'm probably making it way more complicated than it needs to be and can't seem to work it out. Some help with how to go about this would be MUCH appreciated!
I have 1 workbook containing 2 sheets (XR & Issues)
Sheet XR contains 2 Columns A (SearchString) & B (IDKeyArray)
Sheet Issues contains 2 Columns A (IDKey) & B (Labels)
I want to loop through each row of Column A in Sheet XR to see if (SearchString) is found while looping through each row of Column B (Label) in Sheet Issues
Each time the string is found I want to add the Value of Column A (IDKeys) in sheet Issues to an array and then paste the array with all those IDKeys of the array into Column B (IDKeyArray) in Sheet XR
This is what the sheets look like at the start:
Sheet XR:
SearchString IDKeyArray
XR-001
XR-002
XR-003
Sheet Issues:
IDKey Labels
100001 XR-003, reopened, to check, XR-002
100002 XR-001, XR-003 look into, closed
100003 XR-002, reopened, XR-001, Blocked
100004 Reopened, to check, XR-003
And once the code is run I want Sheet XR took look like this:
Sheet XR:
SearchString
XR-001
XR-002
XR-003
IDKeyArray
100002, 100003
100001, 100003
100001, 100004
Horrible not finished code:
Sub StringSearch()
'To search for Strings in XR in Labels in Issues
Sheets("XR").Select
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
'Uses the ActiveSheet
With ActiveSheet
'Sets the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'loop from Lastrow to Firstrow (bottom to top)
For Lrow = LastRow To Firstrow Step -1
'We check the values in the A column
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
StringLabelSearch (Cells(Lrow, 1).Value)
'Send Value to StringLabelSearch
End If
End With
Next Lrow
End With
End Sub
Sub StringLabelSearch(XRString)
Sheets("Issues").Select
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim refConcentrations As Variant
Dim XR As String
XR = XRString
' Init array to a very large size on init >> will optimize at the end of the code
ReDim refConcentrations(1 To 1000) As Variant
'Uses the ActiveSheet
With ActiveSheet
'Sets the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'loop from Lastrow to Firstrow (bottom to top)
For Lrow = LastRow To Firstrow Step -1
'We check the values in the A column
With .Cells(Lrow, "B")
If Not IsError(.Value) Then
If Cells(Lrow, 1).Value = XR Then
'Return
End If
End With
Next Lrow
End With
ReDim Preserve refConcentrations(1 To j - 1) ' <-- resize array to number of elements found
End Sub
I have 1 workbook containing 2 sheets (XR & Issues)
Sheet XR contains 2 Columns A (SearchString) & B (IDKeyArray)
Sheet Issues contains 2 Columns A (IDKey) & B (Labels)
I want to loop through each row of Column A in Sheet XR to see if (SearchString) is found while looping through each row of Column B (Label) in Sheet Issues
Each time the string is found I want to add the Value of Column A (IDKeys) in sheet Issues to an array and then paste the array with all those IDKeys of the array into Column B (IDKeyArray) in Sheet XR
This is what the sheets look like at the start:
Sheet XR:
SearchString IDKeyArray
XR-001
XR-002
XR-003
Sheet Issues:
IDKey Labels
100001 XR-003, reopened, to check, XR-002
100002 XR-001, XR-003 look into, closed
100003 XR-002, reopened, XR-001, Blocked
100004 Reopened, to check, XR-003
And once the code is run I want Sheet XR took look like this:
Sheet XR:
SearchString
XR-001
XR-002
XR-003
IDKeyArray
100002, 100003
100001, 100003
100001, 100004
Horrible not finished code:
Sub StringSearch()
'To search for Strings in XR in Labels in Issues
Sheets("XR").Select
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
'Uses the ActiveSheet
With ActiveSheet
'Sets the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'loop from Lastrow to Firstrow (bottom to top)
For Lrow = LastRow To Firstrow Step -1
'We check the values in the A column
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
StringLabelSearch (Cells(Lrow, 1).Value)
'Send Value to StringLabelSearch
End If
End With
Next Lrow
End With
End Sub
Sub StringLabelSearch(XRString)
Sheets("Issues").Select
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim refConcentrations As Variant
Dim XR As String
XR = XRString
' Init array to a very large size on init >> will optimize at the end of the code
ReDim refConcentrations(1 To 1000) As Variant
'Uses the ActiveSheet
With ActiveSheet
'Sets the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'loop from Lastrow to Firstrow (bottom to top)
For Lrow = LastRow To Firstrow Step -1
'We check the values in the A column
With .Cells(Lrow, "B")
If Not IsError(.Value) Then
If Cells(Lrow, 1).Value = XR Then
'Return
End If
End With
Next Lrow
End With
ReDim Preserve refConcentrations(1 To j - 1) ' <-- resize array to number of elements found
End Sub
Last edited: