Results 1 to 4 of 4

Need to copy single cell value to range of cells on different worksheet

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,408

    Need to copy single cell value to range of cells on different worksheet

    Macro should copy the Col C Stock Codes on Order Form to Database Col D four times.
    Then copy each set of Volumes to Database Col E.
    Then copy each Destination to Database Col F.
    Then copy each Delivery Date to Database Col G.
    Result should be like Cols K - N in Database

    Option Explicit
    Dim c As Long, f As Long
    Dim ws As Worksheet, ws2 As Worksheet
    
    Sub NEWORD()
    
        Set ws = Sheet1 ' Order Form
    
        Set ws2 = Sheet2 'Database
    
    'Find next free row on Database
        With ws2
        f = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        If f < 2 Then f = 2
        
    'Copy Codes and Vols to Database
        For c = 4 To 7
        
    'Next line generates Runtime error 1004 -method 'range' of object '_Worksheet' failed
        
    'Copy Stock Codes to Col D of Database
        ws.Range(.Cells(23, 3), .Cells(27, 3)).Copy Destination:=.Cells(f, 4)
        
    'Copy Stock volumes to Col E of Database
        ws.Range(.Cells(23, c), .Cells(27, c)).Copy Destination:=.Cells(f, 5)
    
    'Copy Destinations in relevant col to Col F of Database
        .Range(.Cells(f, 6), .Cells(f + 4, 6)).Value = ws.Cells(14, c).Value
        
    'Copy Scheduled Delivery Date in relevant col to Col G of Database
        .Range(.Cells(f, 7), .Cells(f + 4, 7)).Value = ws.Cells(30, c).Value
        
    'Reset f to next free row
        f = f + 5
    'Repeat until all Destinations complete
        Next
        
        End With
        
        End Sub
    Can't understand why it creates the RunTIme error, but hopefully someone will see the issue?

    All solutions, suggestions and alternatives welcome as ever

    Ochimus

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy/paste range of cells if cell matches another cell in another worksheet
    By Lewis Shoulders in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-16-2018, 07:30 AM
  2. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  3. [SOLVED] VBA code to copy certain cells from one worksheet into a single row in another worksheet
    By thedefense in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2013, 06:11 PM
  4. [SOLVED] copy data from cells in a column on one worksheet to a single cell in another worksheet
    By jpsnickers in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2013, 07:02 PM
  5. Need to Copy range of data from Multiple Workbooks to Single Worksheet
    By nuver101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2013, 12:58 PM
  6. Macro. Copy range of cells (e,g, =A1:B9) and paste it into single cell.
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2011, 09:28 AM
  7. Replies: 2
    Last Post: 12-18-2005, 02:20 AM

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