Hi I am new to coding and everything and I have been learning VBA the last 3 months and right now I am having real difficulty accomplishing this task.
I have multiple CheckBoxes that triggers different events and different combination of checkboxes triggers different events as well. this is why i have module for each checkbox separately
in my last step for the whole workbook i need to get information from another workbook called Input and calculate or add these number to my original workbook.
Everyhing is fine but Vlookup wich has all arguments expet for one exactly the same is ocuring on every module i have so far. that is why i wanted to create some Public Constant or similar which i can just call and the variables that changes i would set manually in the code based on which checkbox it is. But i cant figure out how, always gives me multiple errors.
Original code option i tried before I started trying the Public Constants look like this (is part of the whole code other thinks works fine except for this part)
While having the ConstantsForVlookUp in another module:
I have multiple CheckBoxes that triggers different events and different combination of checkboxes triggers different events as well. this is why i have module for each checkbox separately
in my last step for the whole workbook i need to get information from another workbook called Input and calculate or add these number to my original workbook.
Everyhing is fine but Vlookup wich has all arguments expet for one exactly the same is ocuring on every module i have so far. that is why i wanted to create some Public Constant or similar which i can just call and the variables that changes i would set manually in the code based on which checkbox it is. But i cant figure out how, always gives me multiple errors.
Original code option i tried before I started trying the Public Constants look like this (is part of the whole code other thinks works fine except for this part)
VBA Code:
'For Specifications and Calculations
Call Vlookup_setup.ConstantsForVlookUP
'set up for Vlookup the hours
LookUpValue = "SG Long"
'set up for Vlookup the amounts
HeaderValue1 = "SG Long"
FinalHours = Application.WorksheetFunction.VLookup(LookUpValue, LookUpRange, MatchHeader, False)
MatchHeader1 = Application.WorksheetFunction.Match(HeaderValue1, LookUpHeaders1, 0)
'when box gets checked
If Sheet1.Shapes("g-long").OLEFormat.Object.Value = 1 Then
Sheet3.Range("C7").Value = Sheet3.Range("C7") + (FinalHours * 4)
For a = 14 To 22
LookUpValue1 = Sheet3.Cells(a, 1)
FinalAmount = Application.WorksheetFunction.VLookup(LookUpValue1, LookUpRange1, MatchHeader1, False)
Sheet3.Cells(a, 3).Value = Sheet3.Cells(a, 3) + FinalAmount
Next a
'when box gets unchecked
Else
Sheet3.Range("C7").Value = Sheet3.Range("C7") - (FinalHours * 4)
For a = 14 To 22
LookUpValue1 = Sheet3.Cells(a, 1)
FinalAmount = Application.WorksheetFunction.VLookup(LookUpValue1, LookUpRange1, MatchHeader1, False)
Sheet3.Cells(a, 3).Value = Sheet3.Cells(a, 3) - FinalAmount
Next a
End If
While having the ConstantsForVlookUp in another module:
VBA Code:
Sub ConstantsForVlookUP()
'set up for Vlookup the hours
HourTable = "tbl_Hours"
TrailerFT = "45ft"
HeaderRange = "tbl_Hours[#Headers]"
LookUpRange = Workbooks("Input for everything.xlsm").Sheets("Components").Range(HourTable)
LookUpHeaders = Workbooks("Input for everything.xlsm").Sheets("Components").Range(HeaderRange)
MatchHeader = Application.WorksheetFunction.Match(TrailerFT, LookUpHeaders, 0)
'set up for Vlookup the amounts
AmountTable = "tbl_45ftamounts"
HeaderRange1 = "tbl_45ftamounts[#Headers]"
LookUpRange1 = Workbooks("Input for everything.xlsm").Sheets("Components").Range(AmountTable)
LookUpHeaders1 = Workbooks("Input for everything.xlsm").Sheets("Components").Range(HeaderRange1)
End Sub