+ Reply to Thread
Results 1 to 18 of 18

Copying data over to another sheets specific cells

Hybrid View

  1. #1
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Copying data over to another sheets specific cells

    This is the data I want to copy over:

    in sheet 1 column and I would like it pasted in sheet 2 column 1.
    sheet 1 column 9 and paste it in sheet 2 column 2
    sheet 1 column 4 and paste in sheet 2 column 3
    sheet 1 column 7 and paste in sheet 2 column 4
    sheet 1 column 12 and paste in sheet 2 column 5

    This is my current code

    Option Explicit

    Sub status()

    Application.ScreenUpdating = False

    Dim x As Long, eRow As Long
    x = 8

    With Worksheets("Master Bid Sheet")
    Do While Not IsEmpty(.Cells(x, 9))
    Select Case .Cells(x, 9).Value
    Case "Closed", "Accepted"

    With Worksheets("Construction Management")
    eRow = .Cells(.Rows.Count, 9).End(xlUp).Offset(1, 0).Row
    End With
    .Rows(x).Copy Destination:=Worksheets("Construction Management").Rows(eRow)

    End Select
    x = x + 1
    Loop
    End With
    Application.ScreenUpdating = True
    End Sub


    I know I need to replace .Rows(x).Copy Destination:=Worksheets("Construction Management").Rows(eRow) with new code. Can anyone help?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    Please use code tags with your code.
    Which ones are sheets1 and 2 in your code?

  3. #3
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Sorry about that I didn't know I will next time. However, the master bid sheet is sheet 1 and construction management is sheet2

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    Currently, the code looks at Case "Closed", "Accepted", variable rows, column 9, it then copies the entire row in to sheet construction mg.
    What would happen to these condition when you copy the columns? Or do you just want to copy the columns in to cons mg sheet?

  5. #5
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Yes I just want the columns copied over not the entire row. And the information in the columns. But it has to be either closed or accepted it cannot be active or rejected (the other information in the cells)

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    If you are copying to column 9

       ms.Range("I" & eRow).Resize(, 5) = a

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    Untested

    Option Explicit
    
     Sub status()
    
     Application.ScreenUpdating = False
    
     Dim eRow As Long, ms As Worksheet, LR&, i&, a
    
     Set ms = Worksheets("Construction Management")
       eRow = ms.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
     With Worksheets("Master Bid Sheet")
        LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
            For i = 8 To LR
                Select Case .Cells(i, 9).Value
                  Case "Closed", "Accepted"
                   a = Array(.Cells(i, "A").Value, .Cells(i, "I").Value, .Cells(i, "D").Value, .Cells(i, "G").Value, .Cells(i, "L").Value)
                 ms.Range("A" & eRow).Resize(, 5) = a
                End Select
            Next i
     End With
     Application.ScreenUpdating = True
     End Sub

  8. #8
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Thanks for the help, however this is not doing anything when I run it. Any suggestions?

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    Do you rows starting from 8 in column 9 which have either "Closed", "Accepted"?

    Case "Closed", "Accepted"
    INTO
    Case Is = "Closed", "Accepted"

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    Corrected.

    Option Explicit
    
     Sub status()
    
     Application.ScreenUpdating = False
    
     Dim eRow As Long, ms As Worksheet, LR&, i&, a
    
     Set ms = Worksheets("Construction Management")
     With Worksheets("Master Bid Sheet")
        LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
            For i = 1 To LR
                Select Case .Cells(i, 9).Value
                  Case "Closed", "Accepted"
                    eRow = ms.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
                   a = Array(.Cells(i, "A").Value, .Cells(i, "I").Value, .Cells(i, "D").Value, .Cells(i, "G").Value, .Cells(i, "L").Value)
                   ms.Range("A" & eRow).Resize(, 5) = a
                End Select
            Next i
     End With
     Application.ScreenUpdating = True
     End Sub
    Last edited by AB33; 06-17-2013 at 10:51 AM.

  11. #11
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Yes it can either be closed or accepted. However, it is getting copied from column 9 in sheet1 and being pasted in column 2 of sheet 2. I uploaded a document of what it looks like and what I want it to look like, maybe this will help?
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    My corrected code does exactly

  13. #13
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Is there a reason it won't work in the actual spreadsheet? It works in the document I uploaded but not the actual spreadsheet I am using this for?

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    Do you have the same sheet names as the sample? If not, you need to change the names. Or,
    Go to the code itself. Put the cursor inside the code and press F8 which able you to step over line by line and will tell us if there is any error on the code.

  15. #15
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Yes i have the same worksheet names for the spreadsheets. It says: Object variable or With block variable not set for:

    eRow = ms.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
    I know this isn't in code tag, can you tell me how to also?
    Last edited by cobydobbs; 06-17-2013 at 11:08 AM. Reason: got it

  16. #16
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    [code]
    your code
    [code]

    Or highlight your code, press the pound sign from quick reply #
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 20010
    Posts
    30

    Re: Copying data over to another sheets specific cells

    Why does this work in the original spreadsheet but not in the actual one I want to use. Also it is still saying that
    eRow = ms.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
    is wrong?

  18. #18
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying data over to another sheets specific cells

    eRow = ms.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
    INTO

    eRow = Worksheets("Construction Management").Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
    I suspect your sheet name is wrong- may have a space, or typo.
    erow should also be a long variable.

+ 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