hello,
i would like to have unique numbers in a selected range from a different range with defined range values. As you can se i got values that repeate. also i dont know how can i more define randbetweeen. Yes it works but the logic is not really cler for me.
i made it work so the value is compered with just one uper cell value. i would like to compere it with range of values before this from "jed" till one before . I hope i explane my problem clear.
Private Sub CommandButton2_Click()
Dim zadena As Long
Dim xrow As Long
Dim zaddva As Long
Dim dan As Long
Sheets("izbira").Range("O10:O16").ClearContents
For dan = 1 To 7
If Sheets("izbira").Cells(9 + dan, 15).Offset(0, -1).Value = 1 Then
zadena = Sheets("izbira").Cells(Rows.Count, 3).End(xlUp).Row
Sheets("izbira").Range("A4").Value = zadena
Do
xrow = Application.RandBetween(4, zadena)
Sheets("izbira").Cells(9 + dan, 15).Value = Sheets("izbira").Cells(xrow, 3).Value
Loop Until Sheets("izbira").Cells(9 + dan, 15).Value <> Sheets("izbira").Cells(8 + dan, 15).Value
ElseIf Sheets("izbira").Cells(9 + dan, 15).Offset(0, -1).Value = 2 Then
zaddva = Sheets("izbira").Cells(Rows.Count, 9).End(xlUp).Row
Sheets("izbira").Range("A5").Value = zaddva
Do
xrow = Application.RandBetween(4, zaddva)
Sheets("izbira").Cells(9 + dan, 15).Value = Sheets("izbira").Cells(xrow, 9).Value
Loop Until Sheets("izbira").Cells(9 + dan, 15).Value <> Sheets("izbira").Cells(8 + dan, 15).Value
End If
Next dan
End Sub
i would like to have unique numbers in a selected range from a different range with defined range values. As you can se i got values that repeate. also i dont know how can i more define randbetweeen. Yes it works but the logic is not really cler for me.
i made it work so the value is compered with just one uper cell value. i would like to compere it with range of values before this from "jed" till one before . I hope i explane my problem clear.
Private Sub CommandButton2_Click()
Dim zadena As Long
Dim xrow As Long
Dim zaddva As Long
Dim dan As Long
Sheets("izbira").Range("O10:O16").ClearContents
For dan = 1 To 7
If Sheets("izbira").Cells(9 + dan, 15).Offset(0, -1).Value = 1 Then
zadena = Sheets("izbira").Cells(Rows.Count, 3).End(xlUp).Row
Sheets("izbira").Range("A4").Value = zadena
Do
xrow = Application.RandBetween(4, zadena)
Sheets("izbira").Cells(9 + dan, 15).Value = Sheets("izbira").Cells(xrow, 3).Value
Loop Until Sheets("izbira").Cells(9 + dan, 15).Value <> Sheets("izbira").Cells(8 + dan, 15).Value
ElseIf Sheets("izbira").Cells(9 + dan, 15).Offset(0, -1).Value = 2 Then
zaddva = Sheets("izbira").Cells(Rows.Count, 9).End(xlUp).Row
Sheets("izbira").Range("A5").Value = zaddva
Do
xrow = Application.RandBetween(4, zaddva)
Sheets("izbira").Cells(9 + dan, 15).Value = Sheets("izbira").Cells(xrow, 9).Value
Loop Until Sheets("izbira").Cells(9 + dan, 15).Value <> Sheets("izbira").Cells(8 + dan, 15).Value
End If
Next dan
End Sub