Home > Software engineering >  Replace vba cell references
Replace vba cell references

Time:09-22

The younger brother have a vba issue card for a long time, hope god can teach:
Cells in the formula, for example: "=sum (' [book1. XLSX] sheet1! X18, '[book2. XLSX] sheet2! This A67) ", how to extract the formula of reference, such as the first time to extract the '[book1. XLSX] sheet1! X18, through some methods will be the reference replace '[book5. XLSX] sheet1! A1, then replaced the value assigned to the original formula of the original position, the final result into "=sum (' [book5. XLSX] sheet1! A1, '[book2. XLSX] sheet2! A67)
"Note: the cell formula used in the method of uncertain, may for the sum, also may as +, -, *, N () * 1, and so on

CodePudding user response:

 Sub Macro1 () 
'orientation to your actual unit'
Range (" A1 "). Select
'replacement'
ActiveCell. Formula=Replace (ActiveCell. The Formula, "'/book1. XLSX sheet1! X18 ", "' [book5. XLSX] sheet1! A1 ")
'debugging validation'
The Debug. Print ActiveCell. Formula
End Sub

CodePudding user response:

Thank you very much!
Have a question want to ask, how could this formula of reference in this out?

CodePudding user response:

There is no ready-made way,
Need to parse formula,

CodePudding user response:

refer to the second floor librezth response:
thank you very much!
Have a question want to ask, how could this formula of reference in this out?

This part of the possible,
Have a DirectPrecedents properties range, can be found in the same cell in the sheet, but for reference across the worksheet is helpless...
  •  Tags:  
  • VBA
  • Related