ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using the ActiveCell function on 2 different worksheets (https://www.excelbanter.com/excel-programming/364446-using-activecell-function-2-different-worksheets.html)

CatherineN

Using the ActiveCell function on 2 different worksheets
 

I have 2 worksheets in a workbook, and I need to be able to select
cell or row from each worksheet and be able to find out which ro
number each of them are in.
I know that to get one you use ActiveCell.Row, but is there any way t
do this specifying the sheet it is comming from, so I can do it for
different sheets in the same macro?
Thanks
Catherin

--
Catherine
-----------------------------------------------------------------------
CatherineN's Profile: http://www.excelforum.com/member.php...fo&userid=3546
View this thread: http://www.excelforum.com/showthread.php?threadid=55247


Dave Peterson

Using the ActiveCell function on 2 different worksheets
 
I think you're going to have to activate each of the worksheets.

Option Explicit

Sub testme()

Dim wks1 As Worksheet
Dim wks2 As Worksheet

Dim Row1 As Long
Dim Row2 As Long

Set wks1 = Worksheets("Sheet1")
Set wks2 = Worksheets("Sheet2")

With wks1
.Select
Row1 = ActiveCell.Row
End With

With wks2
.Select
Row2 = ActiveCell.Row
End With

MsgBox Row1 & vbLf & Row2

End Sub

CatherineN wrote:

I have 2 worksheets in a workbook, and I need to be able to select a
cell or row from each worksheet and be able to find out which row
number each of them are in.
I know that to get one you use ActiveCell.Row, but is there any way to
do this specifying the sheet it is comming from, so I can do it for 2
different sheets in the same macro?
Thanks
Catherine

--
CatherineN
------------------------------------------------------------------------
CatherineN's Profile: http://www.excelforum.com/member.php...o&userid=35469
View this thread: http://www.excelforum.com/showthread...hreadid=552479


--

Dave Peterson

CatherineN[_2_]

Using the ActiveCell function on 2 different worksheets
 

no luck :confused: and if i had ANY idea what i was doing, maybe
could attempt to make a minor change to make it work... it says it i
out of range but I dont have any idea what that means. Thanks for th
help thoug

--
Catherine
-----------------------------------------------------------------------
CatherineN's Profile: http://www.excelforum.com/member.php...fo&userid=3546
View this thread: http://www.excelforum.com/showthread.php?threadid=55247


Dave Peterson

Using the ActiveCell function on 2 different worksheets
 
I'm betting that you got an error on one of these two lines:

Set wks1 = Worksheets("Sheet1")
Set wks2 = Worksheets("Sheet2")

In my test workbook, my worksheets were named Sheet1 and sheet2.

What are your sheet names?

Put those names in that code.


CatherineN wrote:

no luck :confused: and if i had ANY idea what i was doing, maybe I
could attempt to make a minor change to make it work... it says it is
out of range but I dont have any idea what that means. Thanks for the
help though

--
CatherineN
------------------------------------------------------------------------
CatherineN's Profile: http://www.excelforum.com/member.php...o&userid=35469
View this thread: http://www.excelforum.com/showthread...hreadid=552479


--

Dave Peterson

CatherineN[_3_]

Using the ActiveCell function on 2 different worksheets
 

Thank you I got it working :)


--
CatherineN
------------------------------------------------------------------------
CatherineN's Profile: http://www.excelforum.com/member.php...o&userid=35469
View this thread: http://www.excelforum.com/showthread...hreadid=552479



All times are GMT +1. The time now is 09:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com