bradyjoosse
New Member
- Joined
- Mar 15, 2022
- Messages
- 27
- Gender
- Male
- HSC
- 2023
Hey,
I've currently got to do a decision tree and decision table for my decision support system assesment task, as well as this knowledge being important for the HSC, I am kind of lost on how both work. My visual basic macro code is below which takes inputs from form elements in excel then filters and displays data, I really don't understand what to do as I have looked at a bunch of past examples and videos and still don't understand it.
I've currently got to do a decision tree and decision table for my decision support system assesment task, as well as this knowledge being important for the HSC, I am kind of lost on how both work. My visual basic macro code is below which takes inputs from form elements in excel then filters and displays data, I really don't understand what to do as I have looked at a bunch of past examples and videos and still don't understand it.
Rich (BB code):
Sub FilterButton()
Dim wsRawData As Worksheet
Dim wsFilter As Worksheet
Dim wsOutput As Worksheet
Dim rngRawData As Range
Dim rngFilter As Range
Dim rngOutput As Range
Dim criteriaRange As Range
Dim Budget As Single
Dim DownloadSpeed As Integer
Dim UploadSpeed As Integer
Dim Provider As String
Application.ScreenUpdating = False
' Set references to the relevant worksheets
Set wsRawData = ThisWorkbook.Worksheets("Raw Data")
Set wsFilter = ThisWorkbook.Worksheets("NewHomeandInput")
Set wsOutput = ThisWorkbook.Worksheets("Filtered Data")
' Set the range to be filtered (Raw Data range)
Set rngRawData = wsRawData.Range("A2:I99")
' Set the range where filtered data will be outputted (Output Sheet)
Set rngOutput = wsOutput.Range("A2")
' Get the filter criteria from the Filter Sheet
Budget = wsFilter.Range("V14").Value
DownloadSpeed = wsFilter.Range("V15").Value
UploadSpeed = wsFilter.Range("V16").Value
Provider = wsFilter.Range("V18").Value
'Clear previous filtered data before importing the new data
Sheets("Filtered Data").Select
Range("A2:H99").Select
Selection.ClearContents
' Clear any previous filters in the Raw Data range
wsRawData.AutoFilterMode = False
' Apply the filter based on the criteria in the Filter Sheet
With rngRawData
.AutoFilter Field:=5, Criteria1:="<=" & DownloadSpeed ' Column F
.AutoFilter Field:=6, Criteria1:="<=" & UploadSpeed ' Column G
.AutoFilter Field:=8, Criteria1:="<=" & Budget ' Column I
If Provider <> "Any" Then
.AutoFilter Field:=2, Criteria1:=Provider ' Column B
End If
End With
' Copy the visible cells (filtered data) to the Output Sheet, including the header row
rngRawData.SpecialCells(xlCellTypeVisible).Copy Destination:=rngOutput
ActiveWorkbook.Worksheets("Filtered Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Filtered Data").Sort.SortFields.Add2 Key:=Range( _
"E2:E42"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Filtered Data").Sort.SortFields.Add2 Key:=Range( _
"G2:G42"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Filtered Data").Sort.SortFields.Add2 Key:=Range( _
"F2:F42"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Filtered Data").Sort
.SetRange Range("A1:H42")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("NewHomeandInput").Select
Range("J2").Select
' Turn off the AutoFilter
wsRawData.AutoFilterMode = False
' Clear the clipboard
Application.CutCopyMode = False
' Autofit columns after pasting data
Application.ScreenUpdating = True
End Sub