VBA : How to compare values from one column and write in another

Alex Silva

New Member
Joined
Nov 17, 2017
Messages
3
I'm having problems comparing the values in column R and getting the row with the smallest number and assign the largest value available in column B and don't know how to do it.

In the screenshoot bellow i have data that i got from the "Tarefas e Tempos" button
http://prntscr.com/hikhix

With this data in the next button "Maqs" i will define the amount of machines that i want to divide the workload In this example i chose 4 machines and this is the output
https://prnt.sc/hikj82

So as you can see the program goes from the largest to the smallest number in column B. This means that machine 1 will always be the one with the highest total, total from machine 2 will be higher than machhine 3 and so on.

My question is how can i make the program do what is doing in this example for column M but in column N find the lowest total in column R and write in that row but in column N the next number.
In this example it should become this

http://prntscr.com/hikpnh

Can somebody help me?

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">PrivateSub CommandButton3_Click()
Worksheets
("Sheet1").Activate

Range
("A1").Value ="j"
Range
("B1").Value ="pj"
Range
("E3").Value ="ultima celula em A"
Range
("E4").Value = Range("A1").End(xlDown).Row
Range
("E1").Value ="total tarefas"
Range
("E2").Value = Cells(4,5).Value -1

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


Range
("L1").Value ="máqs a usar?"
Dim M AsLong
M
= Application.InputBox(Prompt:="N maq?", Type:=1)

DoWhile M <2
M
= Application.InputBox(Prompt:="N maq? ", Type:=1)
Loop

If M > Rows.Count Then
M
= Rows.Count
EndIf


Range
("F1").Value ="total maqs"
Range
("F2").Value = M
Range
("F3").Value ="colunas a fazer"
colunasAfazer
= Range("E2").Value / Range("F2").Value
Range
("F4").Value = colunasAfazer
Range
("F5").Value ="arredondamento"
Range
("F6").Value = Round(colunasAfazer +0.44)
arredondado
= Range("F6").Value


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


contador
=0

Range
("R1").Value ="Total"
Range
("R2").Value =0
Range
("R3").Value =0


Dim j, q AsInteger
For j =12To arredondado +11
For i =2To M +1
q
= i -1

Range
("R"& i)= WorksheetFunction.Sum(Range("M"& i &":Q"& i))

If(Cells(i, j))<>""Then

contador
= contador +1

Cells
(i, j +1)= WorksheetFunction.Large(Columns(2), contador)

Range
("R"& i)= WorksheetFunction.Sum(Range("M"& i &":Q"& i))

EndIf
Next i
Next j

EndSub</code>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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