unique number in a range

er19

New Member
Joined
Dec 4, 2022
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
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.
1670183733934.png


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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top