+ Reply to Thread
Results 1 to 5 of 5

copy data to another workbook with 3 numbers in three rows and other text copy 3times

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2013
    Location
    Munich, Germany
    MS-Off Ver
    Excel 2010
    Posts
    16

    copy data to another workbook with 3 numbers in three rows and other text copy 3times

    I have now a input sheet with a Macro button that copies the input data into another worksheet.

    the input sheet look like this:

    Name: [ ]
    Score (math): [ ]
    score (art): [ ]
    score(gym): [ ]

    After the input and clicking a button, it now copies the input in one row: name, score (math), score (art), score(gym)

    But I want a entry in three rows:

    Name, Score, Course
    XX , ##1 , math
    XX , ##2 , art
    XX , ##3 , gym

    so, the macro need to copy the field Name three times, with the same value, and the numbers together with course names seperately into three rows.

    in the following code cells F7,F8,F9 contains numbers and C7,C8,C9 are different criteria, C4,C5 are general text.
    Please help. Thanks!

    Sub UpdateLogWorksheet()
    
        Dim historyWks As Worksheet
        Dim inputWks As Worksheet
    
        Dim nextRow As Long
        Dim oCol As Long
    
        Dim myRng As Range
        Dim myCopy As String
        Dim myInput As String
        Dim myCell As Range
        
        'cells to copy from Input sheet - some contain formulas
        myCopy = "C4,C5,C7,C8,C9,F7,F8,F9"
    
        Set inputWks = Worksheets("Input")
        Set historyWks = Worksheets("SubData")
    
        With historyWks
            nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
        End With
    
        With inputWks
            Set myRng = .Range(myCopy)
    
            If Application.CountA(myRng) <> myRng.Cells.Count Then
                MsgBox "Please fill in all the cells!"
                Exit Sub
            End If
        End With
    
        With historyWks
            With .Cells(nextRow, "A")
                .Value = Now
                .NumberFormat = "mmddhhmmss"
            End With
            .Cells(nextRow, "B").Value = Application.UserName
            oCol = 3
            For Each myCell In myRng.Cells
                historyWks.Cells(nextRow, oCol).Value = myCell.Value
                oCol = oCol + 1
            Next myCell
        End With
        
        'clear input cells that contain constants
        With inputWks
            On Error Resume Next
        Range("C7:C9").Select
        Range("C7").Activate
        Selection.ClearContents
        Range("C4").Select
             End With
          On Error GoTo 0
    
    End Sub
    Last edited by lazybone; 05-15-2013 at 10:24 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: copy data to another workbook with 3 numbers in three rows and other text copy 3times

    Does the code give you errors?

    Do you have a sample file that you can upload?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    05-15-2013
    Location
    Munich, Germany
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: copy data to another workbook with 3 numbers in three rows and other text copy 3times

    i have uploaded the sample file, and how I want it to be changed in the "Subdata" sheet.

    Thanks a lot!!
    Attached Files Attached Files

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: copy data to another workbook with 3 numbers in three rows and other text copy 3times

    What is the issue with the existing code you posted?

    Also, incase HD has a blank value, do you still want the row to be populated for the other fields and show 0 for HD?

  5. #5
    Registered User
    Join Date
    05-15-2013
    Location
    Munich, Germany
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: copy data to another workbook with 3 numbers in three rows and other text copy 3times

    i want it to show 0. The code I posted has no problem. but it is recording all information into one row. But I want each of the numbers to be recorded into seperate rows. I put the example on the work sheet in the same file.

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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