Hi when running this code while the first check box "cb_crude" IS NOT ticked i get a "object required" error from the "if not usePrices is nothing then" line. Do I have to define usePrices as "" to make it an object? It's weird because the same code worked for an example workbook.. 
Sub updatebutton()
'define variables
Dim wb As Workbook
Dim presentation, prices_sheet, volumes_sheet, pavEvaluated As Worksheet
Dim cb_crude, cb_fuel, cb_gas, cb_dest As CheckBox
Dim allPrices, usePrices, allVolumes, useVolumes As Range
'set workbook and worksheets
Set wb = ThisWorkbook
Set presentation = wb.Sheets("Presentation")
Set prices_sheet = wb.Sheets("Prices")
Set volumes_sheet = wb.Sheets("Volumes")
Set pavEvaluated = wb.Sheets("Prices and Volumes evaluated")
'set check boxes
Set cb_crude = presentation.CheckBoxes("Check Box Crude")
Set cb_fuel = presentation.CheckBoxes("Check Box Fuel")
Set cb_gas = presentation.CheckBoxes("Check Box Gas")
Set cb_dest = presentation.CheckBoxes("Check Box Dest")
'set ranges
Set allPrices = prices_sheet.Range("A1").CurrentRegion
Set allPrices = allPrices.Offset(4, 1).Resize(allPrices.Rows.Count - 4, allPrices.Columns.Count - 1)
Set allVolumes = volumes_sheet.Range("A1").CurrentRegion
Set allVolumes = allVolumes.Offset(2, 2).Resize(allVolumes.Rows.Count - 2, allVolumes.Columns.Count - 2)
'Set what happens when the check boxes are ticked
If cb_crude.Value = 1 Then
Set usePrices = allPrices.Columns("A:O")
Set useVolumes = allVolumes.Columns("A:O")
End If
If cb_fuel.Value = 1 Then
If Not usePrices Is Nothing Then
Set usePrices = Union(usePrices, allPrices.Columns("P:X"))
Set useVolumes = Union(useVolumes, allVolumes.Columns("P:X"))
Else
Set usePrices = allPrices.Columns("P:X")
Set useVolumes = allVolumes.Columns("P:X")
End If
End If
If cb_gas.Value = 1 Then
If Not usePrices Is Nothing Then
Set usePrices = Union(usePrices, allPrices.Columns("Y:DA"))
Set useVolumes = Union(useVolumes, allVolumes.Columns("Y:DA"))
Else
Set usePrices = allPrices.Columns("Y:CZ")
Set useVolumes = allVolumes.Columns("Y:CZ")
End If
End If
If cb_dest.Value = 1 Then
If Not usePrices Is Nothing Then
Set usePrices = Union(usePrices, allPrices.Columns("DA:DC"))
Set useVolumes = Union(useVolumes, allVolumes.Columns("DA:DC"))
Else
Set usePrices = allPrices.Columns("DA:DC")
Set useVolumes = allVolumes.Columns("DA:DC")
End If
End If
If Not usePrices Is Nothing Then
usePrices.Copy pavEvaluated.Range("A1")
useVolumes.Copy pavEvaluated.Cells(Rows.Count, "A").End(xlUp).Offset(2, 0)
End If
End Sub
Bookmarks