currently i have this

in this 1 button i ask the number of jobs and randomize the time for those jobs between 1 and 10 in columm B
PrivateSub Button1_Click()

Worksheets
("Sheet1").Activate

Range
("A1").Value ="tarefa"
Range
("B1").Value ="tempo"

Dim N AsLong
N
= Application.InputBox(Prompt:="N tarefas?(ex. 7 = 6 tarefas)", Type:=1)
If N > Rows.Count Then
N
= Rows.Count
EndIf

For Z =2To N
Cells
(Z,1)= Z -1
Cells
(Z,2)= WorksheetFunction.RandBetween(1,10)
Next Z
Range
("E1").Value ="total tarefas"
Range
("E2").Value = N -1
Range
("E7").Value ="ultima celula em A"
Range
("E8").Value = Range("A1").End(xlDown).Row

EndSub
in this 2 button i order the values from column B from the greatest to the smallest i ask the number of machines and list the machines i also determine the number of columns that will be needed to be made according to the jobs and the number of machines chosen
PrivateSub Button2_Click()
Worksheets
("Sheet1").Activate

Columns
("A:B").Select
Selection
.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom
:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1
:=xlSortNormal

Range
("L1").Value ="mqs a usar?"
Dim N AsLong
M
= Application.InputBox(Prompt:="N maq?(ex. 3 = 2 maq)", Type:=1)
If M <3Then
M
=3
EndIf
If M > Columns.Count Then
M
= Columns.Count
EndIf

Range
("E4").Value ="total maqs"
Range
("E5").Value = M -1

For i =2To M
Cells
(i,12)= i -1
Next i

Range
("E10").Value ="colunas a fazer"
colunasAfazer
=(Cells(2,5)/ Cells(5,5))
Range
("E11").Value = colunasAfazer
Range
("E13").Value ="arredondamento"
Range
("E14").Value = Round(Cells(11,5)+0.44)
arredondado
= Range("E14").Value

For q =1To M
w
= q +1
the problem comes here i m trying to get the program to start in line 2 (w=2) column L see if is empty and if is not (because it will have the machines listed there) then go to column M and write the first, second, third and so on bigger number of column B to do only this i don t have a problem
SelectCase Cells(w,12)
CaseIs=""
CaseElse
Cells
(w,13)= WorksheetFunction.Large(Columns(2), q)
EndSelect
Next q
EndSub
what i tried and failed to do is get this to be automatic instead of having to do the following that kinda works sometines
SelectCase Cells(w,12)
CaseIs=""
CaseElse
Cells
(w,13)= WorksheetFunction.Large(Columns(2), q)
EndSelect

SelectCase Cells(w,13)
CaseIs=""
CaseElse
Cells
(w,14)= WorksheetFunction.Large(Columns(2), w + M -1)
EndSelect
Next q
EndSub
^Can anyone help me to make this part automatic to fill the necessary cells with the right q value with any number of jobs and machines chosen ?