I am trying to created a comparison script to compare 2 dynamic arrays and then input a into a cell. So i would pull from column D and E and put information from Column F with a number added onto it.

So the example of my process is:
Load column D and E into dynamic arrays,
Compare D to E,
IF D = E then F will equal Column C & "-" & Count and Increase D
IF D != E then I need to increase E and compare it to D

The IF statements are giving me trouble. Here's my code:

Private Sub CommandButton1_Click()

Dim r As Long, i As Long, q As Long, count As Integer

Dim nums() As Variant, scol() As Variant, opnum As Variant

r = 2
i = 0
ReDim nums(0)
Do Until Cells(r, 2).Value = ""
    nums(i) = Cells(r, 2).Value
    i = i + 1
ReDim Preserve nums(i)
r = r + 1
Loop


r = 2
i = 0
ReDim scol(0)
Do Until Cells(r, 4).Value = ""
    scol(i) = Cells(r, 4).Value
    i = i + 1
ReDim Preserve scol(i)
r = r + 1
Loop


count = 1
i = 0
q = 0

Do
If nums(i) = scol(q) Then Cells(q + 2, 7) = Cells(q + 2, 6) & "-" & count
q = q + 1
i = i + 1
count = count + 1

Loop Until q = 50

End Sub

This Part needs to be Redone, I need to impliment the IF statements with maybe a for loop?

Do
If nums(i) = scol(q) Then Cells(q + 2, 7) = Cells(q + 2, 6) & "-" & count
q = q + 1
i = i + 1
count = count + 1

Loop Until q = 50

I need some Guidance.
Thank you.

Hi Nole diver,

Is there any chance you can upload your workbook without sensitive or private data. It would be a big help if you provided a before and after scenario to go along with it. This way we can know for certain what your requirements are.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.