+ Reply to Thread
Results 1 to 3 of 3

Expand range help

  1. #1
    David
    Guest

    Expand range help

    I use the following to keep cells between two sheets in sync:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Lrow As Long
    On Error GoTo ws_exit:
    Lrow = Cells(Rows.Count, 3).End(xlUp).Row
    If Target.Count > 1 Then GoTo ws_exit
    If Intersect(Target, Range("C3:C" & Lrow)) Is Nothing Then GoTo ws_exit
    Application.EnableEvents = False
    Sheets(2).Range("B18").Offset(Target.Row, 0) = Target.Value
    ws_exit:
    Application.EnableEvents = True
    End Sub

    What I would like to do is expand its range to include source columns E and
    F, skipping D and include target columns C and D


    --
    David

  2. #2
    David
    Guest

    Re: Expand range help

    I worked out the first part:
    If Intersect(Target, Range("C3:C" & Lrow, "E3:F" & Lrow)) Is Nothing Then
    GoTo ws_exit

    Still can't get the second, presumably because there is one less column on
    sheet 2. I can't change that due to other routines in my project.

    --
    David

    David < wrote

    > I use the following to keep cells between two sheets in sync:
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim Lrow As Long
    > On Error GoTo ws_exit:
    > Lrow = Cells(Rows.Count, 3).End(xlUp).Row
    > If Target.Count > 1 Then GoTo ws_exit
    > If Intersect(Target, Range("C3:C" & Lrow)) Is Nothing Then GoTo
    > ws_exit Application.EnableEvents = False
    > Sheets(2).Range("B18").Offset(Target.Row, 0) = Target.Value
    > ws_exit:
    > Application.EnableEvents = True
    > End Sub
    >
    > What I would like to do is expand its range to include source columns
    > E and F, skipping D and include target columns C and D
    >
    >



  3. #3
    David
    Guest

    Re: Expand range help

    Got it:
    If Target.Column > 3 Then
    Sheets(2).Range("B18").Offset(Target.Row, Target.Column - 4) = Target.Value
    Else
    Sheets(2).Range("B18").Offset(Target.Row, 0) = Target.Value
    End If

    --
    David

    David < wrote

    > Still can't get the second, presumably because there is one less
    > column on sheet 2. I can't change that due to other routines in my
    > project.



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1