Consulting

Results 1 to 11 of 11

Thread: Solved: Copy one cell to another using VBA

  1. #1
    VBAX Regular
    Joined
    Mar 2008
    Location
    Texas
    Posts
    19
    Location

    Solved: Copy one cell to another using VBA

    This sounds simple but all I want to do is once I enter a value in M3 and tab to next cell for that value to be copied to cell M5 using VBA. The issue is once I move past M3 or I think it's "LostFocus" I want it to copy. Thanks in advance.

    I'm lost. My simple code so far is:

    Range("M3:N3").Select
    Selection.Copy
    Range("M5:N5").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You only need

    [vba]

    Range("M3:N3").Copy Range("M5:N5")
    [/vba]

    but that should work. Is it part of a Worksheet_Change event? If so, shouldn't you use Target?
    ____________________________________________
    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 Regular
    Joined
    Mar 2008
    Location
    Texas
    Posts
    19
    Location
    Yes, it's part of a Worksheet_Change event. The problem is that If I type a value in cell M3 and move past M3 I need it copy the value to M5, but only if there is a value in M3.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Show us the code mate.
    ____________________________________________
    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 Regular
    Joined
    Mar 2008
    Location
    Texas
    Posts
    19
    Location
    xld, I'm very new to VBA, but learning. The above code is all of the code I have and it is in a module. I have 7 worksheets and need the copy and paste to work in all 7.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this event then

    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "M3" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    .Resize(, 2).Copy .Offset(2, 0)
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/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

  7. #7
    VBAX Regular
    Joined
    Mar 2008
    Location
    Texas
    Posts
    19
    Location
    YOU ARE THE BOMB!!!!! It's knowing where to put it. I have to put it into each sheet not Module1. Thank You...

  8. #8
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    LOL.... you've been called many things Bob, but a "bomb"?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by Aussiebear
    LOL.... you've been called many things Bob, but a "bomb"?

    Ted I think it's "THE Bomb"
    I understand it to be a complement of the highest order. I agree when applied to Bob....

    Kids these days.......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Aussiebear
    LOL.... you've been called many things Bob, but a "bomb"?
    Oh! I just read it as ... you are a bum ... Shows what you are expecting.
    ____________________________________________
    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

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Good lord Bob, you've got your glasses on upside down again...
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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