Consulting

Results 1 to 6 of 6

Thread: link cell in sheet1 to cell in sheet

  1. #1

    link cell in sheet1 to cell in sheet

    cannot get this to work can any one help


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Cells("A1") >= 1 Then
    'Sheets("Sheet2").Select
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=SUM(6*Sheet1!R[-1]C[-1])"
    Range("B3").Select
    End If
    End Sub
    the range B2 is then coppied down to end of row of A:A

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Why is
    Sheets("Sheet2").Select
    remmed out?

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Change If Cells("A1") to Range("A1")

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'm not clear why you want to run this every time you change your selection, or what "copied to the end of Row A:A" means
    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If [A1] >= 1 Then
    Sheets("Sheet2").Range("B2").FormulaR1C1 = "=SUM(6*Sheet1!R[-1]C[-1])"
    With Sheets("Sheet2")
    .Activate
    .[B3].Select
    End With
    End If
    End Sub
    [/vba]
    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'

  5. #5
    Quote Originally Posted by mdmackillop
    I'm not clear why you want to run this every time you change your selection, or what "copied to the end of Row A:A" means
    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If [A1] >= 1 Then
    Sheets("Sheet2").Range("B2").FormulaR1C1 = "=SUM(6*Sheet1!R[-1]C[-1])"
    With Sheets("Sheet2")
    .Activate
    .[B3].Select
    End With
    End If
    End Sub
    [/vba]
    first of all let me say thank you for your reply.
    the reason for running this every time is that the value of "A1" changes with the value of the euro. in order to get the operator to check the current value before he inputs an invoice, as the value of the cell is cleared on exit.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    In that case I would use a different event code
    [vba]
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
    Sheets("Sheet2").Range("B2").FormulaR1C1 = "=SUM(6*Sheet1!R[-1]C[-1])"
    With Sheets("Sheet2")
    .Activate
    .[B3].Select
    End With
    End If
    End Sub
    [/vba]
    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'

Posting Permissions

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