EXCEL MACRO two active cells and their rows

Please post any questions regarding the program here.

Moderator: 2020vision

EXCEL MACRO two active cells and their rows

Postby alrodopial » Tue Oct 01, 2013 5:33 pm

I have selected two cells in a sheet that are not consecutive ie A4 and C12

How do I get their rows number in two variables? VBA
ie MyRow1 = 4, MyRow2 = 12
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Postby osknows » Tue Oct 01, 2013 7:43 pm

This is one way of doing it

Code: Select all
Sub selectedCells()
Dim MyRow1 As Long
Dim MyRow2 As Long
Dim MyAddress() As String

    With Selection
        If .Count = 2 Then
            MyAddress = Split(.Address, ",")
            MyRow1 = Split(MyAddress(0), "$")(2)
            MyRow2 = Split(MyAddress(1), "$")(2)
        End If
    End With
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby alrodopial » Tue Oct 01, 2013 9:19 pm

So with Selection.Address you get ie $A$4 as string and then extract the 4
Thanks os
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm


Return to Help

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 39 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.