Have VBA to link to cell on previous sheet, need to modify to link to last cell in column, eliminate seperate cell

Kusaywa

Board Regular
Joined
Aug 26, 2016
Messages
123
I have a cell on Sheet1 which contains the formula =LOOKUP(2,1/(F:F<>""),F:F)
This gives me the last entry in column F
On Sheet2 and so on, I have this code in a module
Code:
Function PrevSheet(RCell As Range)
    Dim xIndex As Long
    Application.Volatile
    xIndex = RCell.Worksheet.Index
    If xIndex > 1 Then _
        PrevSheet = Worksheets(xIndex - 1).Range(RCell.Address)
End Function
Then have this formula in a cell =PrevSheet(I3)
What I'm trying do is eliminate the separate cell on the previous sheet that contains =LOOKUP(2,1/(F:F<>""),F:F) and somehow just pull the last entry in column F

Thanks for any help
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Put the following code in a module

Code:
Function LastValue(col As String)
    If ActiveSheet.Index > 1 Then
        Dim s As Worksheet
        Set s = Sheets(ActiveSheet.Index - 1)
        LastValue = s.Range(col & s.Range(col & Rows.Count).End(xlUp).Row).Value
    End If
End Function


In sheet2 in a cell put de formula:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]=LastValue("F")[/TD]
[/TR]
</tbody>[/TABLE]

The "F" is the column from which you want to get the last value.
Try an tell me.
 
Upvote 0
Use the following

Code:
Function LastValue(col As String)
    If ActiveSheet.Index > 1 Then
        Dim s As Worksheet
        Dim b As Object
        Set s = Sheets(ActiveSheet.Index - 1)
        Set b = s.Columns(col).Find("*", lookat:=xlWhole, LookIn:=xlValues, SearchDirection:=xlPrevious)
        If Not b Is Nothing Then
            LastValue = s.Range(col & b.Row).Value
        End If
    End If
End Function
 
Upvote 0
It works when first entering =LastValue("F") but when I flip between sheets, it changes to #VALUE !
Same if I place it in a cell that's not a formula
 
Upvote 0
That's right, I also have problems with the function, I review it and comment on it.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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