Noob question about referenced cells and worksheets

serivas

New Member
Joined
May 6, 2016
Messages
2
Hi there!

I'm making a subroutine that uses a cell reference as an input (the active cell).

My question is: If I pass a range as "ByRef NAME As Variant", does "NAME" have a worksheet "attached" to it, or is it just a location on the active worksheet?

For instance:

Sub Add(ByRef NAME As Variant, j As Integer, k As Integer)

Dim A As Integer

A = NAME.Row + NAME.Column + (NAME's worksheet index/number)
' how would I add NAME's worksheet number?

End Sub

Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I think you want to pass NAME as a Range, not a Variant.

On a Range object you can call the Parent property which has an Index property.

For example:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim str As String
 str = Target.Parent.Index 'Sets str to index number of worksheet
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,579
Messages
6,120,365
Members
448,956
Latest member
Adamsxl

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