Consulting

Results 1 to 7 of 7

Thread: Solved: Define range and combine two codes

  1. #1
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location

    Solved: Define range and combine two codes

    Hi,

    Can someone please help me with following two things:

    1) Change the range (Set rg = Range("A2:K5001") to dynamic range.
    (Only the rows increase)
    2) Combine both the codes into one.

    Thanks.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rg As Range, rgRow As Range
    On Error GoTo ExitHere
    Set rg = Range("A2:K5001")
    If Intersect(rg, Target) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    For Each rgRow In Intersect(Target, rg).Rows
    Cells(rgRow.Row, "L") = Now()
    Next rgRow
    ExitHere:
    Application.EnableEvents = True
    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'check cells for desired format to trigger the calendarfrm.show routine
    'otherwise exit the sub
    Dim DateFormats, DF
    DateFormats = Array("m/d/yy;@", "mmmm d yyyy")
    For Each DF In DateFormats
    If DF = Target.NumberFormat Then
    If CalendarFrm3.HelpLabel.Caption <> "" Then
    CalendarFrm3.Height = 191 + CalendarFrm.HelpLabel.Height
    Else: CalendarFrm3.Height = 191
    CalendarFrm3.Show
    End If
    End If
    Next
    End Sub
    -u

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why would you want to coimbine them, one is actioned on change, one on selection?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    I am sorry, I think it would be ok to keep it this way.

    I would like to know about the dynamic range however. Thanks xld.
    Last edited by U_Shrestha; 04-01-2008 at 09:28 AM.
    -u

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How about simply

    [vba]

    Set rg = Range("A:K")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    Great!! Thanks so much.
    -u

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi U,
    Please remember to use the VBA button to format posted code.
    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'

  7. #7
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    [VBA][/VBA] Got it. Thanks.

Posting Permissions

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