Vlookup with constants in different module and variables

Manificco

New Member
Joined
Nov 23, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
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)

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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top