Spreadsheet.MergeVariables

This function merges the spreadsheet variables with the variables of the specified file.

Syntax Parameters Return Value
Sub Spreadsheet.MergeVariables( _
    Input As Variant, _
    Optional Mode As Variant, _
    Optional UnmatchedCases As Variant, _
    Optional Key1 As Variant, _
    Optional Key2 As Variant, _
    Optional CompareText As Variant, _
    Optional Order As Variant, _
    Optional VerifyVariables As Variant)
  • Input [in]

The fully-qualified pathway to the file that will be merged.

Type: Variant

  • Mode [in,optional]

The method for handling the merge if the number of cases between the two spreadsheets are not equal. The available constants for this parameter are: scMergeNotRelational, scMergeRelational, scMergeRelationalHierarchical. Note that this parameter defaults to scMergeNotRelational.

Type: Variant

  • UnmatchedCases [in,optional]

The method for handling unmatched cases that may occur from not meeting the relational criteria. The available constants for this parameter are: scMergeFillWithMD, scMergeDelete, scMergeAbort. Note that this parameter defaults to scMergeFillWithMD.

Type: Variant

  • Key1 [in,optional]

The variable to be used as the key in the first spreadsheet.

Type: Variant

  • Key2 [in,optional]

The variable to be used as the key in the second spreadsheet.

Type: Variant

  • CompareText [in,optional]

The key comparison method. The available constants for this parameter are: scMergeText, scMergeNumeric. Note that this parameter defaults to scMergeNumeric.

Type: Variant

  • Order [in,optional]

The order to be used if variable verification is enabled.

Type: Variant

  • VerifyVariables [in,optional]

Whether or not to verify the key sorting for hierarchical merging.

Type: Variant

This function does not return a value.

SVB Example

Merging spreadsheets by variables:

Option Base 1
Option Explicit
Sub Main
    Dim spr As Spreadsheet
    'opens the spreadsheet smoking2.sta and assigns it to the object spr
    Set spr = Spreadsheets.Open(Path & "\examples\datasets\smoking2.sta")
    spr.Visible = True
    'merges the file smoking3 with the smoking 2
    'performs a non-relational merge
    'deletes unmatched cases
    'merges based on text
    'variable 1 is the key in both spreadsheets
    spr.MergeVariables(Path & "\examples\datasets\smoking3.sta", _
    scMergeNotRelational, _
    scMergeDelete,1,1,scMergeText)
End Sub