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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,521
Messages
6,125,307
Members
449,218
Latest member
Excel Master

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