Consulting

Results 1 to 4 of 4

Thread: Solved: Select Row problem

  1. #1

    Question Solved: Select Row problem

    I tried this code to show message only if I select any row in a sheets else exit sub but didn't work
    [VBA]Dim wsh As Worksheet
    If Not wsh.Rows.Select Then Exit Sub
    MsgBox ("ok")[/VBA]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Put this in the ThisWorkbook module

    [vba]Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim Rws
    Rws = Target.Cells.Count / Sh.Columns.Count
    If Rws - Int(Rws) = 0 Then MsgBox Rws & " rows selected"
    End Sub
    [/vba]
    Last edited by mdmackillop; 02-14-2011 at 02:33 AM. Reason: Minor correction
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    thank you for help!!

  4. #4
    thank you for help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •