You are on page 1of 9

Dim i As Integer, Added As Double, Cost As Double, SumaProdRev As Double, ProdRev As Double,

UserPrice As Double, NetPrice As Single, RelNum As Integer

UserPrice = Worksheets("Data").Range("I2").Value

NetPrice = Worksheets("Data").Range("J2").Value

RelNum = Worksheets("Data").Range("C2").Value

For i = 2 To 12

UserPrice = Worksheets("Data").Range("I" & i).Value

NetPrice = Worksheets("Data").Range("J" & i).Value

RelNum = Worksheets("Data").Range("C" & i).Value

Added = (UserPrice - (NetPrice / RelNum))

Cost = NetPrice / RelNum

ProdRev = Added / Cost

SumaProdRev = SumaProdRev + ProdRev

Next i

Worksheets("Dashboard").Range("C22").Value = UserPrice

Sub DashOutStock()

Dim i As Long, OutStock As Single

For i = 2 To 45700

If Worksheets("Datos").Range("H" & i).Value = 0 Then

OutStock = OutStock + 1

Worksheets("Dashboard").Range("F13:G19").Value = OutStock

End If

Next i

End Sub
Sub DashAvgPrice()

Dim i As Long, Avg As Double, Price As Double, TotalPrice As Double, Items As Integer, TotalItems
As Long

For i = 2 To 45700

Price = Worksheets("Datos").Range("F" & i).Value

Items = Worksheets("Datos").Range("H" & i).Value

TotalItems = TotalItems + Items

TotalPrice = TotalPrice + (Price * Items)

Avg = TotalPrice / TotalItems

Next

Worksheets("Dashboard").Range("D13:E19").Value = Avg

End Sub

Sub DashAvgLowPrice()

Dim i As Long, Avg As Double, LowPrice As Double, TotalPrice As Double, Items As Long, TotalItems
As Long

For i = 2 To 45700

LowPrice = Worksheets("Datos").Range("J" & i).Value

Items = Worksheets("Datos").Range("H" & i).Value

TotalItems = TotalItems + Items

TotalPrice = TotalPrice + (LowPrice * Items)

Avg = TotalPrice / TotalItems

Next

Worksheets("Dashboard").Range("J13:K19").Value = Avg

End Sub

Sub NewestRel()

Dim i As Long, Year As Double, ID As Long, Newest As Double

For i = 2 To 45700

Year = Worksheets("Datos").Range("G" & i).Value


ID = Worksheets("Datos").Range("A" & i).Value

If Year = 2018 Then

Newest = ID

End If

Worksheets("Dashboard").Range("B13:C19").Value = Newest

Next

End Sub

Sub ClasABC()

Dim i As Integer, Suma As Double, Percent As Double

For i = 2 To 1200

Percent = Range("Q" & i).Value

Suma = Suma + Percent

Range("R" & i).Value = Suma

Next i

End Sub

Sub ClassicABC()

Dim TotPrice As Single, i As Integer, Price As Single, Units As Integer, Avg As Single, Tot As Integer

For i = 2 To 1200

Units = Range("H" & i).Value

Price = Range("I" & i).Value


TotPrice = (Units * Price)

Avg = ((TotPrice / 537711.9375) * 100)

Range("P" & i).Value = Avg

Next

End Sub

Class = Range("K" & i + 1).Value

TotalPrice = Range("D" & i).Value

If Class = "C1" Then

G1 = G1 + TotalPrice

ElemC1 = ElemC1 + 1

Cent1 = (G1 / ElemC1)

End If

If Class = "C2" Then

G2 = G2 + TotalPrice

ElemC2 = ElemC2 + 1

Cent2 = (G2 / ElemC2)

End If

If Class = "C3" Then

G3 = G3 + TotalPrice

ElemC3 = ElemC3 + 1

Cent3 = (G3 / ElemC3)

End If

TotalPrice = Range("D" & i).Value


If Class = "C1" Then

G1 = G1 + TotalPrice

ElemC1 = ElemC1 + 1

Cent1 = (G1 / ElemC1)

End If

If Class = "C2" Then

G2 = G2 + TotalPrice

ElemC2 = ElemC2 + 1

Cent2 = (G2 / ElemC2)

End If

If Class = "C3" Then

G3 = G3 + TotalPrice

ElemC3 = ElemC3 + 1

Cent3 = (G3 / ElemC3)

End If

Sub Quicksort(vArray As Variant, arrLbound As Long, arrUbound As Long)

'Sorts a one-dimensional VBA array from smallest to largest

'using a very fast quicksort algorithm variant.

Dim pivotVal As Variant

Dim vSwap As Variant

Dim tmpLow As Long

Dim tmpHi As Long

tmpLow = arrLbound

tmpHi = arrUbound

pivotVal = vArray((arrLbound + arrUbound) \ 2)


While (tmpLow <= tmpHi) 'divide

While (vArray(tmpLow) > pivotVal And tmpLow < arrUbound)

tmpLow = tmpLow + 1

Wend

While (pivotVal > vArray(tmpHi) And tmpHi > arrLbound)

tmpHi = tmpHi - 1

Wend

If (tmpLow <= tmpHi) Then

vSwap = vArray(tmpLow)

vArray(tmpLow) = vArray(tmpHi)

vArray(tmpHi) = vSwap

tmpLow = tmpLow + 1

tmpHi = tmpHi - 1

End If

Wend

If (arrLbound < tmpHi) Then Quicksort vArray, arrLbound, tmpHi 'conquer

If (tmpLow < arrUbound) Then Quicksort vArray, tmpLow, arrUbound 'conquer

End Sub

Sub ProcessData_Quicksort()

'Example macro to show you how to add a column of data to an array

'and sort the data from smallest to largest using VBA Quicksort.

Dim MyData() As Variant

Dim i As Long, LastRow As Long, j As Long


'Store column of data into array

LastRow = Range("K" & Rows.Count).End(xlUp).Row

ReDim MyData(LastRow, 10)

For i = 1 To LastRow

For j = 1 To 10

MyData(i, 1) = Range("A" & i + 1).Value

MyData(i, 2) = Range("B" & i + 1).Value

MyData(i, 3) = Range("C" & i + 1).Value

MyData(i, 4) = Range("D" & i + 1).Value

Next j

Next i

'Now sort your array using the VBA Quicksort macro

Call Quicksort(MyData(), LBound(MyData), UBound(MyData))

'

'From here on, your "MyData" array is sorted from smallest to largest

For i = 1 To LastRow

Range("O" & i + 1) = MyData(i, 1)

Range("P" & i + 1) = MyData(i, 2)

Range("Q" & i + 1) = MyData(i, 3)

Range("R" & i + 1) = MyData(i, 4)

Next

End Sub

Do While Rep < 1

Rep = Rep + 1

Dis1 = Abs(TotalPrice - Range("G2").Value)

Dis2 = Abs(TotalPrice - Range("G3").Value)


Dis3 = Abs(TotalPrice - Range("G4").Value)

Range("H" & i).Value = Dis1

Range("I" & i).Value = Dis2

Range("J" & i).Value = Dis3

If Dis1 < Dis2 And Dis1 < Dis3 Then

Class = "C1"

ElseIf Dis2 < Dis1 And Dis2 < Dis3 Then

Class = "C2"

ElseIf Dis3 < Dis1 And Dis3 < Dis2 Then

Class = "C3"

End If

Range("K" & i).Value = Class

TotalPrice = Range("D" & i).Value

If Class = "C1" Then

G1 = G1 + TotalPrice

ElemC1 = ElemC1 + 1

Cent1 = (G1 / ElemC1)

End If

If Class = "C2" Then

G2 = G2 + TotalPrice

ElemC2 = ElemC2 + 1

Cent2 = (G2 / ElemC2)

End If
If Class = "C3" Then

G3 = G3 + TotalPrice

ElemC3 = ElemC3 + 1

Cent3 = (G3 / ElemC3)

End If

Range("L1").Value = Range("G2").Value

Range("M1").Value = Range("G3").Value

Range("N1").Value = Range("G4").Value

Range("G2").Value = Round(Cent1, 2)

Range("G3").Value = Round(Cent2, 2)

Range("G4").Value = Round(Cent3, 2)

Loop

You might also like