Consulting

Results 1 to 5 of 5

Thread: Solved: VBA code to copy range to another specific range

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location

    Solved: VBA code to copy range to another specific range

    I currently have a growing database listing on sheet ("Database") starting at A2:H2 and down to last row,(last row can be determined by Col A. I would like to copy that over to the worksheet("Query") starting at range A11:H11. When pasting it will be overwriting existing data.

    How is this done?
    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With Worksheets("Database")

    .Range(.Range("A2:H2"), .Range("A2:H2").End(xlDown)).Copy Worksheets("Query").Range("A11")
    End With
    [/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

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Thanks Bob, so the messages you would normally recieve when doing it manually don't need responding to when doing it by VBA?
    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

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    I've created a button on the Query sheet which calls the Sub RefreshData
    [VBA]
    Sub cmdRefresh_Click()
    Call RefreshData
    End Sub
    [/VBA]

    then used your code to copy and paste


    [VBA]Sub RefreshData()

    With Worksheets("Database")
    .Range(.Range("A2:H2"), .Range("A2:H2").End(xlDown)).Copy Worksheets("Query").Range("A11")
    End With

    End Sub[/VBA]

    so that if I change the any of the data on the Database worksheet either by adding or changing the sort order it updates the Query data accordingly
    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

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why don't you tie it to the Change event?
    ____________________________________________
    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

Posting Permissions

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