Using shared variables requires two formulas: one to store the value in a shared variable, the other to retrieve the value from the shared variable.
The most important thing to remember when using shared variables is that Crystal Reports must first evaluate the formula where the value is stored before evaluating the formula that retrieves the shared variable. In other words, the first formula (in the subreport) needs to be in a section above the second formula (in the main report).

For example, in order to pass a grand total value from a subreport to the main report, follow these steps:

1. In the subreport, create a formula similar to the one below:

//Stores the grand total of the {Gifts.Gift Amount} field in a currency variable called 'myTotal'

Shared CurrencyVar myTotal := Sum ({Gift.Gift Amount})

2. Place this formula in the Report Footer of your subreport

3. In the main report, create a formula that declares the same variable name:

//Returns the value that was stored in the shared currency variable called myTotal in the subreport

Shared CurrencyVar myTotal;

4. Place @MainFormula in a section that is beneath the section containing the subreport.

NOTE: For the shared variable to return the correct value in the main report, you must place @MainFormula in a main report section that is beneath the section containing the subreport. This ensures Crystal Reports evaluates the @SubFormula before @MainFormula.

One way to do this is to insert a section below the section containing the subreport, and place @MainFormula in this new sub-section:

  • Go to Report > Section (in Crystal XI) or Format > Section (in Crystal 8.5)
  • On the Sections list, highlight the section containing the subreport.
  • Click Insert (at top of dialog box). This inserts an additional subsection.
  • Click OK to return to the report, and insert @MainFormula into this new sub-section.

The next time you preview the report, @MainFormula displays the value from the subreport. In this particular example, that value was the grand total of the {Gift.Gift Amount} field.

5. Once you have verified that @MainFormula is returning the correct value from the subreport, you can include this formula in other main report formulas, such as:

//includes data from subreport

{@MainFormula} + Sum ({Gift.Gift_Amount})

Place this formula in the same section as @MainFormula, or in a section further down on the report.

NOTE: This is not possible with On Demand Subreports in Crystal Reports since the report will not be processed until after clicking report.

Please review How to use variables (BB570) on creating formulas with variables.
For more information on how to create shared variables, please refer to the this MSDN article.
For more information consider this blog post from SAP: Passing values between reports in Crystal Reports 2008