Function that returns a string

masterkemist

New Member
Joined
Feb 1, 2005
Messages
11
I have a relative sheet reference function that returns a string as in

refonprevsheetname("G10")

I understand that it is a string but I want the row number to change as I move down the column. This way I can drag the fill handle down instead of typing each one out. Can anyone offer any solutions?
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Brian from Maui

MrExcel MVP
Joined
Feb 16, 2002
Messages
8,458
masterkemist said:
I have a relative sheet reference function that returns a string as in

refonprevsheetname("G10")

I understand that it is a string but I want the row number to change as I move down the column. This way I can drag the fill handle down instead of typing each one out. Can anyone offer any solutions?

I maybe missing something here, but

=SheetName!G10

and drag down
 

masterkemist

New Member
Joined
Feb 1, 2005
Messages
11
Yeah...

I want the next row down to read

refonprevsheetname("G11")

then

refonprevsheetname("G12")

then

refonprevsheetname("G13")

etc, etc, etc.

Does that make more sense or am I missing something. After all, I am a newbie :pray:
 

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
You could do it by incorporating the ROW() function. For example, if your first formula is in row 5, you could use:

=refonprevsheetname("G"&ROW()+5)

Not a very elegant approach but it will work. Hope that helps!
 

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,201

ADVERTISEMENT

masterkemist said:
I have a relative sheet reference function that returns a string as in

refonprevsheetname("G10")

I understand that it is a string but I want the row number to change as I move down the column. This way I can drag the fill handle down instead of typing each one out. Can anyone offer any solutions?

That must be a UDF. Not sure it can handle a result from another function, but it should...


=refonprevsheetname(CELL("Address",G10))
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Tom

Do you really need to pass a string to the UDF?

Perhaps you could post the code for the UDF and an explanation of what it's supposed to do?
 

masterkemist

New Member
Joined
Feb 1, 2005
Messages
11
Sure... I'd be happy to post the udf vba code

Code:
'this will return a cell from the previous sheet'
Function RefOnPrevSheetName(Addr As String) As Variant
    Application.Volatile True
    With Application.Caller.Parent
    If .Index = 1 Then
        RefOnPrevSheetName = _
        .Parent.Worksheets.Range(Addr).Value
    Else
        RefOnPrevSheetName = .Previous.Range(Addr).Value
    End If
    End With
End Function

If you have any more elegant solutions, I'm totally open. I am very much a newbie to vba. :LOL:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,719
Messages
5,597,733
Members
414,170
Latest member
Mdm

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
Top