+ Reply to Thread
Results 1 to 7 of 7

Change cell value and macro runs

Hybrid View

Macdave_19 Change cell value and macro... 11-21-2007, 06:34 AM
StephenR Your syntax isn't quite... 11-21-2007, 07:44 AM
Macdave_19 OK so lose the contradiction... 11-21-2007, 10:41 AM
BigBas Are you asking how to make a... 11-21-2007, 10:58 AM
stevekirk hi Macdave_19, is the idea... 11-21-2007, 10:58 AM
Macdave_19 Yes steve it is mate!! 11-23-2007, 04:09 AM
stevekirk hi are you having... 11-23-2007, 04:18 AM
  1. #1
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Change cell value and macro runs

    Hi folks i'm having trouble getting this code to work!! i would like certain cell values to change when i update the range B4 but i don't know quite how to set the range as b4?

    any help is much appreciated, here is my code

    Private Sub Worksheet_Change(ByVal Target As Range)
        Set Target = Range("B4")
        Dim SAgent As String
        SAgent = Range("B4").Value
        
            If Target.Value <> SAgent Then
                Range("E4,E24,H4,H13,H23,H33,K4,K18,K30").Value = SAgent
            End If
    End Sub
    Thanks for taking the time to view my thread everyone and for any help
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Your syntax isn't quite right, but I don't follow. You appear to be setting SAgent to equal Target (B4) but the second If only works if Target doesn't equal SAgent which by definition cannot happen?

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim SAgent As String
        If Target = Range("B4") then
        SAgent = Range("B4").Value
       
            If Target.Value <> SAgent Then
                Range("E4,E24,H4,H13,H23,H33,K4,K18,K30").Value = SAgent
            End If
    end if
    End Sub

  3. #3
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question

    OK so lose the contradiction in there and im still left with:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim SAgent As String
        If Target = Range("B4") then
        SAgent = Range("B4").Value
            
        Range("E4,E24,H4,H13,H23,H33,K4,K18,K30").Value = SAgent
           
    End If
    End Sub

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Are you asking how to make a change if the target is cell B4?

    If so, try this code:

    If Target.Address = "$B$4"
    Otherwise, I'm not sure what you are asking.

  5. #5
    Forum Contributor
    Join Date
    08-10-2006
    Posts
    723
    hi Macdave_19,

    is the idea of this macro to change all the cells in the range to what is in b4 ?

    steve

  6. #6
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808
    Yes steve it is mate!!

  7. #7
    Forum Contributor
    Join Date
    08-10-2006
    Posts
    723
    hi

    are you having problems with the code you last posted ?

    the reason i ask is because i wanted something like this and it works for me

    steve

+ 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