Hi,
I have four integers stored in four variables. I need to sort these, and in a descending order put into appropriate cells (A1, B1, C1, D1). However, there also can be a string instead of one integer
I managed to find the integers, and store them into variables. I also managed to identify if string is selected and store it into appropriate cell (must be A1).
But how do I fianalize macro with sorting four / three integers and putting into appropriate cells? I mean the elegant way, not the ultra-super-If-Else-if type of code, but using probably the BubbleSort?
Here's the begging of the code:
I have four integers stored in four variables. I need to sort these, and in a descending order put into appropriate cells (A1, B1, C1, D1). However, there also can be a string instead of one integer
I managed to find the integers, and store them into variables. I also managed to identify if string is selected and store it into appropriate cell (must be A1).
But how do I fianalize macro with sorting four / three integers and putting into appropriate cells? I mean the elegant way, not the ultra-super-If-Else-if type of code, but using probably the BubbleSort?
Here's the begging of the code:
Code:
Dim wb As Workbook, ws_wk_dlt As Worksheet, ws_dash As Worksheet, _
frcst_act As Variant, SOP_numb As Integer, SOP_year As Integer, cell_B6 As Variant, _
cell_C6 As Variant, cell_D6 As Variant, cell_E6 As Variant, SOP_key_B6 As Integer, SOP_key_C6 As Integer, SOP_key_D6 As Integer, SOP_key_E6 As Integer
'Referencing
Set wb = ThisWorkbook
Set ws_wk_dlt = wb.Worksheets("UMBCCA PivotDelta (wk)")
Set ws_dash = wb.Worksheets("UMBCCA Dashboard")
'Values from pivot stored
cell_B6 = ws_wk_dlt.Range("B6").Value
cell_C6 = ws_wk_dlt.Range("C6").Value
cell_D6 = ws_wk_dlt.Range("D6").Value
cell_E6 = ws_wk_dlt.Range("E6").Value
'If len certain amount of chartacters then do option 1, or option 2
If cell_B6 <> "" Then
If Len(cell_B6) = 12 And cell_B6 <> "Actual Sales" Then
SOP_key_B6 = CInt(Mid(cell_B6, 4, 2)) + CInt(Mid(cell_B6, 8, 4))
ElseIf Len(cell_B6) = 11 And cell_B6 <> "Actual Sales" Then
SOP_key_B6 = CInt(Mid(cell_B6, 4, 2)) + CInt(Mid(cell_B6, 7, 4))
End If
End If
If cell_C6 <> "" Then
If Len(cell_C6) = 12 And cell_C6 <> "Actual Sales" Then
SOP_key_C6 = CInt(Mid(cell_C6, 4, 2)) + CInt(Mid(cell_C6, 8, 4))
ElseIf Len(cell_C6) = 11 And cell_C6 <> "Actual Sales" Then
SOP_key_C6 = CInt(Mid(cell_C6, 4, 2)) + CInt(Mid(cell_C6, 7, 4))
End If
End If
If cell_D6 <> "" Then
If Len(cell_D6) = 12 And cell_D6 <> "Actual Sales" Then
SOP_key_D6 = CInt(Mid(cell_D6, 4, 2)) + CInt(Mid(cell_D6, 8, 4))
ElseIf Len(cell_D6) = 11 And cell_D6 <> "Actual Sales" Then
SOP_key_D6 = CInt(Mid(cell_D6, 4, 2)) + CInt(Mid(cell_D6, 7, 4))
End If
End If
If cell_E6 <> "" Then
If Len(cell_E6) = 12 And cell_E6 <> "Actual Sales" Then
SOP_key_E6 = CInt(Mid(cell_B6, 4, 2)) + CInt(Mid(cell_E6, 8, 4))
ElseIf Len(cell_E6) = 11 And cell_E6 <> "Actual Sales" Then
SOP_key_E6 = CInt(Mid(cell_E6, 4, 2)) + CInt(Mid(cell_E6, 7, 4))
End If
End If
'Finding the Actual Sales and putting into L30
If cell_B6 = "Actual Sales" Then
ws_dash.Range("A1").Value = cell_B6
ElseIf cell_C6 = "Actual Sales" Then
ws_dash.Range("A1").Value = cell_C6
ElseIf cell_D6 = "Actual Sales" Then
ws_dash.Range("A1").Value = cell_D6
ElseIf cell_E6 = "Actual Sales" Then
ws_dash.Range("A1").Value = cell_E6
End If