+ Reply to Thread
Results 1 to 4 of 4

Editing macro to put the information in the correct place

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Editing macro to put the information in the correct place

    I got thise code from Jerry's Excel Assistant and it was ASWESOME!!!!!!!!!!

    https://sites.google.com/a/madrocket...-into-template

    The only problem now is that I want the data from cells A2, B2, & D2 in the "Data" tab to be input into D3, D2, & I2 respectively into the "Survey" copied template and then A3, B3, & D3 and so on until there is no more data to be input into the same cells on the new sheet. PLease helppppppppppppp!!!!!!!!!! I think the red text is where i'm going sour.

    test sheet2.xlsm

    Option Explicit
    
    Sub FillOutTemplate()
    'Jerry Beaucaire  4/25/2010
    'From Sheet1 data fill out template on sheet2 and save
    'each sheet as its own file.
    Dim LastRw As Long, Rw As Long, Cnt As Long
    Dim dSht As Worksheet, tSht As Worksheet
    Dim MakeBooks As Boolean, SavePath As String
    
    Application.ScreenUpdating = False  'speed up macro execution
    Application.DisplayAlerts = False   'no alerts, default answers used
    
    Set dSht = Sheets("Data")           'sheet with data on it starting in row2
    Set tSht = Sheets("Template")       'sheet to copy and fill out
    
    'Option to create separate workbooks
        MakeBooks = MsgBox("Create separate workbooks?" & vbLf & vbLf & _
            "YES = template will be copied to separate workbooks." & vbLf & _
            "NO = template will be copied to sheets within this same workbook", _
                vbYesNo + vbQuestion) = vbYes
    
    If MakeBooks Then   'select a folder for the new workbooks
        MsgBox "Please select a destination for the new workbooks"
        Do
            With Application.FileDialog(msoFileDialogFolderPicker)
                .AllowMultiSelect = False
                .Show
                If .SelectedItems.Count > 0 Then    'a folder was chosen
                    SavePath = .SelectedItems(1) & "\"
                    Exit Do
                Else                                'a folder was not chosen
                    If MsgBox("Do you wish to abort?", _
                        vbYesNo + vbQuestion) = vbYes Then Exit Sub
                End If
            End With
        Loop
    End If
    
    'Determine last row of data then loop through the rows one at a time
        LastRw = dSht.Range("A" & Rows.Count).End(xlUp).Row
        
        For Rw = 2 To LastRw
            tSht.Copy After:=Worksheets(Worksheets.Count)   'copy the template
            With ActiveSheet                                'fill out the form
                'edit these rows to fill out your form, add more as needed
                .Name = dSht.Range("E" & Rw)
                .Range("A2").Value = dSht.Range("D" & Rw).Value
                .Range("B2").Value = dSht.Range("B" & Rw).Value
                .Range("D2").Value = dSht.Range("I" & Rw).Value            
            End With
            
            If MakeBooks Then       'if making separate workbooks from filled out form
                ActiveSheet.Move
                ActiveWorkbook.SaveAs SavePath & Range("B3").Value, xlNormal
                ActiveWorkbook.Close False
            End If
            Cnt = Cnt + 1
        Next Rw
    
        dSht.Activate
        If MakeBooks Then
            MsgBox "Workbooks created: " & Cnt
        Else
            MsgBox "Worksheets created: " & Cnt
        End If
        
    Application.ScreenUpdating = True
    End Sub
    Last edited by missmea2005; 08-31-2012 at 07:01 AM. Reason: Corrected thread title to topic only

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: I have the Macro I need, but the information is not posting to the correct place

    the syntax of those red cells are "destinationcell.value = sourcecell.value". OK? I think you're just reading it backwards;

                .Name = dSht.Range("E" & Rw)
                .Range("D3").Value = dSht.Range("A" & Rw).Value
                .Range("D2").Value = dSht.Range("B" & Rw).Value
                .Range("I2").Value = dSht.Range("D" & Rw).Value
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-27-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Editing macro to put the information in the correct place

    Bless you bless you!!!!!!!!!!! Thank you soooooooooooooooooooooooo much!!!!!!!!!!!!!!!!!!!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Editing macro to put the information in the correct place

    BTW, when you're trying to adapt one of my macros, be sure to Private Message me a link to threads you've started for that purpose so I can join in, when possible.

    Cheers.

+ 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