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
question from:
https://stackoverflow.com/questions/65830897/vba-paring-a-values-in-an-array-according-to-conditions 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…