opaquefruitcake
New Member
- Joined
- Jan 6, 2019
- Messages
- 2
Hello,
I am writing a program that combines and compares the values in columns 1 and 2 using an array, then changes the color of the row those values appear it if it show up more than once in the spreadsheet. I know there is an easier way to do this with formulas, but the person I am making this for wants it bound to a button, and I figured this was a good opportunity to learn more about arrays. I currently have the loop to assign the values, but am having trouble finding a way to compare those values to each other. Here is what I have so far:
I have attempted to do several If statements to compare the variables to determine if the color of the row should be changed, but I could not figure out a way to test every value in the array against every other one. I also attempted to use a parallel array to test each value, but couldn't figure that out either. Were any of those possible solutions close? Also is there a more efficient way in VBA to do this other than an array? Thanks in advance for any assistance anyone can offer.
I am writing a program that combines and compares the values in columns 1 and 2 using an array, then changes the color of the row those values appear it if it show up more than once in the spreadsheet. I know there is an easier way to do this with formulas, but the person I am making this for wants it bound to a button, and I figured this was a good opportunity to learn more about arrays. I currently have the loop to assign the values, but am having trouble finding a way to compare those values to each other. Here is what I have so far:
Code:
Private Sub strtButton_Click()
Dim lastRow As Long
Dim i As Long
Dim fullValue() As String
Dim j As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
ReDim fullValue(1 To lastRow)
'Determines how many items are in sheet and makes that the length of array fullValue
For i = 1 To lastRow
fullValue(i) = Worksheets("Sheet1").Range("A" & i) & Worksheets("Sheet1").Range("B" & i)
'Assigns each row a value in array fullValue
Range("C" & i) = fullValue(i) 'Used as a test to make sure above formula worked.
Next i
End Sub
I have attempted to do several If statements to compare the variables to determine if the color of the row should be changed, but I could not figure out a way to test every value in the array against every other one. I also attempted to use a parallel array to test each value, but couldn't figure that out either. Were any of those possible solutions close? Also is there a more efficient way in VBA to do this other than an array? Thanks in advance for any assistance anyone can offer.