Hello There,
I have a Sub GetReferenceName which gets a value from the another excel table. This Sub uses parameters as List Object, Range and strings.
The above Sub is called from event Worksheet_Change. I am getting an error on this event on calling this Sub
Error Compile: ByRef argument type mismatch
(highlighted code Call GetReferenceName(pTable:=O_MstTbl_LegalEntities)
Could you please help?
Many thanks & regards,
Don
Below code:
Workbook_open
Assign
Worksheet_Change
GetReferenceName
I have a Sub GetReferenceName which gets a value from the another excel table. This Sub uses parameters as List Object, Range and strings.
The above Sub is called from event Worksheet_Change. I am getting an error on this event on calling this Sub
Error Compile: ByRef argument type mismatch
(highlighted code Call GetReferenceName(pTable:=O_MstTbl_LegalEntities)
Could you please help?
Many thanks & regards,
Don
Below code:
Workbook_open
Code:
Sub Workbook_open
Call Assign;
End Sub
Assign
Code:
Sub Assign
Public MstWB As Workbook
Public MstWSName_LegalEntities As Worksheet
Public MstTblName_LegalEntities As String
Public O_MstTbl_LegalEntities As ListObject
Set MstWB = Workbooks.Open(Filename:=ÄBC.xlsx, ReadOnly:=False, Notify:=False)
'Set Master Worksheets and Master Legal Entities
Set MstWSName_LegalEntities = MstWB.Worksheets("LegalEntities")
MstTblName_LegalEntities = "Tbl_LegalEntities"
Set O_MstTbl_LegalEntities = MstWSName_LegalEntities.ListObjects(MstTblName_LegalEntities)
End Sub
Worksheet_Change
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("FLegalEntityNumber")) Is Nothing Then
Call GetReferenceName(pTable:=O_MstTbl_LegalEntities, _
pFieldRange:=EntWSDE_Header.Range("FLegalEntityNumber"), _
pTableColumnNumber:="Entity Number", _
pTableColumnName:="Entity Name")
End if
GetReferenceName
Code:
Sub GetReferenceName(ByRef pTable As ListObject, _
ByRef pFieldRange As Range, _
ByVal pTableColumnNumber As String, _
ByVal pTableColumnName As String)
Dim fnd As Range
Set fnd = pTable.ListColumns(pTableColumnNumber).DataBodyRange.Find(What:=pFieldRange, LookIn:=xlValues, Lookat:=xlWhole)
If Not fnd Is Nothing Then
[DLegalEntityName] = Intersect(pTable.ListColumns(pTableColumnName).DataBodyRange, fnd.EntireRow).Value
Else
[DLegalEntityName] = "<Name not found in Table Legal Entities.>"
End If
End Sub