+ Reply to Thread
Results 1 to 6 of 6

Creating a log using a macro assigned button

Hybrid View

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    Statesville, NC
    MS-Off Ver
    Excel 2007
    Posts
    5

    Creating a log using a macro assigned button

    I currently have a macro recorded and assigned to a button that completes a simple copy from several different cells on one sheet, named "Input", and pastse them into another sheet, named "Data Log". The recorded macro only pastes the values to the same cells in "Data Log" every time. I need the macro to recognize previously copied and pasted data and paste the values into the next row in the "Data Log". Any advise or help would be greatly appreciated. Below is the recorded macro and the excel file is attached. Thanks!

    Sub Log_Data()
    '
    ' Log_Data Macro
    '

    '
    Range("A2").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C3").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("C5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("D5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("E5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("D9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("F5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C10").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("G5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C13").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("H5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C12").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("I5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C20").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("J5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C21").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("K5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C22").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("L5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("C23").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("M5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("D20").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("N5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("D21").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("O5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("D22").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("P5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Input").Select
    Range("D23").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Data Log").Select
    Range("Q5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,152

    Re: Creating a log using a macro assigned button

    Try this. You'll have to work with formatting your Data Log sheet, but otherwise it should work just fine for you.
    Sub Log_Data()
    '
    ' Log_Data Macro
    '
     Dim LastRow As Long
     Dim WS As Worksheet
     
     Set WS = Sheets("Input")
     
    'Copy from Input to Data Log
    With Sheets("Data Log")
        'Determine last row in a particular column
        LastRow = .Range("B" & Rows.Count).End(xlUp).Row
        
        .Range("B" & LastRow).Offset(1, 0).Value = WS.Range("A2").Value
        .Range("C" & LastRow).Offset(1, 0).Value = WS.Range("C3").Value
        .Range("D" & LastRow).Offset(1, 0).Value = WS.Range("C4").Value
        .Range("E" & LastRow).Offset(1, 0).Value = WS.Range("C9").Value
        .Range("F" & LastRow).Offset(1, 0).Value = WS.Range("D9").Value
        .Range("G" & LastRow).Offset(1, 0).Value = WS.Range("C10").Value
        .Range("H" & LastRow).Offset(1, 0).Value = .Range("E" & LastRow).Offset(1, 0).Value & "x" & .Range("F" & LastRow).Offset(1, 0).Value
        .Range("I" & LastRow).Offset(1, 0).Value = WS.Range("C14").Value
        .Range("J" & LastRow).Offset(1, 0).Value = WS.Range("C20").Value
        .Range("K" & LastRow).Offset(1, 0).Value = WS.Range("C21").Value
        .Range("L" & LastRow).Offset(1, 0).Value = WS.Range("C22").Value
        .Range("M" & LastRow).Offset(1, 0).Value = WS.Range("C23").Value
        .Range("N" & LastRow).Offset(1, 0).Value = WS.Range("D20").Value
        .Range("O" & LastRow).Offset(1, 0).Value = WS.Range("D21").Value
        .Range("P" & LastRow).Offset(1, 0).Value = WS.Range("D22").Value
        .Range("Q" & LastRow).Offset(1, 0).Value = WS.Range("D23").Value
    End With
    
    
    End Sub
    Last edited by jomili; 04-18-2013 at 12:35 PM.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 365 on Win11 (365 on Win11 (desktop), 365 on Win11 (notebook)
    Posts
    8,207

    Re: Creating a log using a macro assigned button

    Hi, cudoig,

    Sub Log_Data()
    '
    ' Log_Data Macro
    '
    
    '
    Dim wsInp As Worksheet
    Dim wsLog As Worksheet
    Dim lngNew As Long
    
    Set wsInp = Sheets("Input")
    Set wsLog = Sheets("Data Log")
    
    With wsLog
      lngNew = .Cells(Rows.Count, "B").End(xlUp).Row + 1
    End With
    
    With wsInp
        wsLog.Cells(lngNew, "B").Value = .Range("A2").Value
        wsLog.Cells(lngNew, "C").Value = .Range("C3").Value
        wsLog.Cells(lngNew, "D").Value = .Range("C4").Value
        wsLog.Cells(lngNew, "E").Value = .Range("C9").Value
        wsLog.Cells(lngNew, "F").Value = .Range("D9").Value
        wsLog.Cells(lngNew, "G").Value = .Range("C10").Value
        wsLog.Cells(lngNew, "H").Value = .Range("C13").Value
        wsLog.Cells(lngNew, "I").Value = .Range("C12").Value
        wsLog.Cells(lngNew, "J").Value = .Range("C20").Value
        wsLog.Cells(lngNew, "K").Value = .Range("C21").Value
        wsLog.Cells(lngNew, "L").Value = .Range("C22").Value
        wsLog.Cells(lngNew, "M").Value = .Range("C23").Value
        wsLog.Cells(lngNew, "N").Value = .Range("D20").Value
        wsLog.Cells(lngNew, "O").Value = .Range("D21").Value
        wsLog.Cells(lngNew, "P").Value = .Range("D22").Value
        wsLog.Cells(lngNew, "Q").Value = .Range("D23").Value
    End With
    
    Set wsLog = Nothing
    Set wsInp = Nothing
    End Sub
    Please use Code-Tags to wrap the procedure.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    04-17-2013
    Location
    Statesville, NC
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Creating a log using a macro assigned button

    Thank you very much for the help!

  5. #5
    Registered User
    Join Date
    04-17-2013
    Location
    Statesville, NC
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Creating a log using a macro assigned button

    Thank you!

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,152

    Re: Creating a log using a macro assigned button

    Posted in error. Ignore this post.
    Last edited by jomili; 04-18-2013 at 12:36 PM.

+ 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