Excel Macros

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eduardo veiga
    New Member
    • Aug 2006
    • 2

    Excel Macros

    What is the problem with the macro : below

    Code:
    Sub M()
    
    C = Worksheets("SHEET1").Range("B5")
    C = ActiveCell
    My_row = ActiveCell.Row
    
    End Sub
    I would like that excel give me back the information of My_Row=5, because that is the row of the Range B5. How can I do this?

    :confused:
    Last edited by acoder; Apr 9 '13, 10:29 PM.
  • michelle
    New Member
    • Jul 2006
    • 11

    #2
    Hello eduardo,

    Try this:

    Code:
    C = Worksheets("SHEET1").Range("B5").Select
    C = ActiveCell
    My_row = ActiveCell.Row
    Nice regards,
    Michelle.
    Last edited by acoder; Apr 9 '13, 10:30 PM.

    Comment

    • dave ellis
      New Member
      • Sep 2006
      • 3

      #3
      Originally posted by eduardo veiga
      : below


      I would like that excel give me back the information of My_Row=5, because that is the row of the Range B5. How can I do this?

      :confused:
      Code:
      Sub M()
      
      C = Worksheets(1).Range("B5").Address
      My_Row = Range(C).Row
      
      MsgBox C       ' you may remove these two lines when finished testing
      MsgBox My_Row  ' you may remove these two lines when finished testing
      
      Range(C).Offset(0, 0).Value = C & ", " & My_Row 
      ' modify the (0, 0) to read (0, 1) for example, and you can see the result being placed to the right of the C range instead of within it
      
      End Sub
      you can now modify this in your choice of ways, to arrive more closely at the result you wanted.

      Comment

      Working...