Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

excel - vba: paring a values in an array according to conditions

I didn′t find any post that could help with my problem that is why I decided to upload a post. I want to make a script that paring the value from one cathegory (H) with the nearest (but lower) value from other cathegory (C), without repetition. One cell value can be used only once. I′m beginer in vba. I am aware that I didn′t write a lot (and probably it isn′t correct), but if someone could help, I will be grateful.

Sub paringdata()

Dim lastrow, erow As Long
Dim i, j, chosedcell As Integer
Dim mydate As Integer
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Sheet1.Range("B7").Select


For i = 2 To lastrow

chosedcell = Cells(i, 2).Value

    For j = 2 To lastrow
        
    If j < chosedcell And j > 300 Then
    erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    Range(Cells(i, 1), Cells(i, 2)).Copy Destination:=Sheets("sheet2").Cells(erow, 1)
    
    Range(Cells(j, 1), Cells(j, 2)).Copy Destination:=Sheets("sheet2").Cells(erow, 1)

    End If
    
    Next j

Next i

End Sub

enter image description here

question from:https://stackoverflow.com/questions/65830897/vba-paring-a-values-in-an-array-according-to-conditions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...