Get value by referencing a cell

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
1,214
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
In E2 of Worksheet “Sheet2” I am using a formula =’7’!H120 which gives me value of cell H120 of the Worksheet with tab named ‘7” as a result in cell E2.

This formula in E2 is variable…it can be =’7’!B100; or =’7’!C555 or any formula like this.
I require an Excel formula in cell E3 of Worksheet “Sheet2” which should give me value of the cell which is $G$2 row below or above (IF G2=1, then 1 row below, IF $G$2=-1, then 1 row above) of the cell address which is being used in cell E2.
G2= an integer value

How to accomplish?
Thanks in advance.



Cross posted in Get value by referencing a cell
Referencing.xlsx
EFG
2221
3999
Sheet2
Cell Formulas
RangeFormula
E2E2='7'!H120
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
In that case try this user-defined function.

VBA Code:
Function myOffset(r As Range, RowOffset As Long) As Variant
  myOffset = Sheets(Replace(Split(Mid(r.Formula, 2), "!")(0), "'", "")).Range(Split(r.Formula, "!")(1)).Offset(RowOffset).Value
End Function
Peter S S Sir,
Can your vba code be further extended to return
The values in L3, M3 & N3 (in the same row)

Note: E2=’7’!H120
Therefore E3 gets the value from the cell address =’7’!H118
Thus, required is: L3=7
M3=H
N3=118
Regards
Referencing.xlsx
H
117466
118115
119913
120121
121296
122812
123578
7

Referencing.xlsx
EFGHIJKLMN
1-2
2121
3myOffset(E2,G1)7H118
Sheet2
Cell Formulas
RangeFormula
E2E2='7'!H120
 
Upvote 0
Use this function instead of the one in that other thread.

VBA Code:
Function FormulaPt(r As Range, lPart As Long, RowOffset As Long) As String
  Dim s As String
  
  s = r.Formula
  Select Case lPart
    Case 1: FormulaPt = Mid(s, 3, 1)
    Case 2: FormulaPt = Mid(s, 6, 1)
    Case 3: FormulaPt = Right(s, 3) + RowOffset
  End Select
End Function

hsandeep.xlsm
EFGHIJKLMN
1-2
21217H118
3115
Sheet2
Cell Formulas
RangeFormula
L2:N2L2=FormulaPt($E2,COLUMNS($L:L),$G1)
E2E2='7'!H120
E3E3=myOffset(E2,G1)



.. or keep using that previous function and just adjust for the row offset when retrieving the third formula part

hsandeep.xlsm
EFGHIJKPQR
1-2
21217H118
3115
Sheet2
Cell Formulas
RangeFormula
P2P2=FormulaPart(E2,1)
Q2Q2=FormulaPart(E2,2)
R2R2=FormulaPart(E2,3)+G1
E2E2='7'!H120
E3E3=myOffset(E2,G1)
 
Upvote 1
Use this function instead of the one in that other thread.

VBA Code:
Function FormulaPt(r As Range, lPart As Long, RowOffset As Long) As String
  Dim s As String
 
  s = r.Formula
  Select Case lPart
    Case 1: FormulaPt = Mid(s, 3, 1)
    Case 2: FormulaPt = Mid(s, 6, 1)
    Case 3: FormulaPt = Right(s, 3) + RowOffset
  End Select
End Function
This is okay. But I also require formulas in L3, M3 & N3.
In above case, for E2='7'!H120,
E3 is '7'!H118 & therefore required
L3=7
M3=H
N3=118

How to accomplish?
 
Upvote 0
Use $G$1 wherever I had G1 or $G1
I had done the above changes, but correct L3, M3, N3 are not getting populated for the respective cell address E3 which has =myOffset(E3,$G$1)
 
Upvote 0
Then you'll have to show me a mini sheet with some relevant sample data and the expected results as I am lost.
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,134
Members
449,206
Latest member
burgsrus

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