+ Reply to Thread
Results 1 to 8 of 8

Combining Two Excel Macros

  1. #1
    Registered User
    Join Date
    07-19-2013
    Location
    Scranton, Pa
    MS-Off Ver
    Excel 2013
    Posts
    14

    Cool Combining Two Excel Macros

    Hello, I am using two separate Macros in two separate Excel documents. I need help combining them. The first Macro I am using will automatically add the current users user name, the time, and the date when a user puts information into column A. So if the users puts something into cell A1 then B1 automatically gets filled with their username and C1 gets filled with the time and date.

    The second Macro automatically locks cells in columns D through I after the user enters data.

    I would like to bring these to Macros together but can not figure it out! Any thoughts or suggestions would be appreciated! Thanks!

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    Dim rCell As Range
    Dim rChange As Range

    On Error GoTo justenditall
    Set rChange = Intersect(Target, Range("D:I"))
    If Not rChange Is Nothing Then
    Application.EnableEvents = False
    For Each rCell In rChange
    If rCell > "" Then
    ActiveSheet.Unprotect Password:="thepassword"
    Target.Locked = True
    End If
    Next
    End If

    ActiveSheet.Protect Password:="thepassword"

    justenditall:
    Application.EnableEvents = True

    End Sub

    -----------------------------------------------
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim rCell As Range
    Dim rChange As Range

    On Error GoTo ErrHandler
    Set rChange = Intersect(Target, Range("A:A"))
    If Not rChange Is Nothing Then
    Application.EnableEvents = False
    For Each rCell In rChange
    If rCell > "" Then
    rCell.Offset(0, 1).Value = UserName()
    rCell.Offset(0, 2).Value = Date & " " & Time()
    Else
    rCell.Offset(0, 1).Clear
    End If
    Next

    End If

    ExitHandler:
    Set rCell = Nothing
    Set rChange = Nothing
    Application.EnableEvents = True
    Exit Sub
    ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler

    End Sub

    Public Function UserName()
    UserName = Environ$("UserName")
    End Function

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Combining Two Excel Macros

    Hello and welcome the forum,

    First, some housekeeping...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Now as for your question, here is what it should look like (untested):
    Please Login or Register  to view this content.
    abousetta
    Last edited by abousetta; 07-19-2013 at 06:24 PM.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    07-19-2013
    Location
    Scranton, Pa
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Combining Two Excel Macros

    Sorry about that format error, next time I will format properly. So this code does everything I want it to.

    If you double click in a cell but then decide not to enter data and click somewhere else an error pops up. After the error comes up nothing works. Anyway to easily fix this?

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Combining Two Excel Macros

    I'm out at the moment. I'll take a look at this later and repost.

    abousetta

  5. #5
    Registered User
    Join Date
    07-19-2013
    Location
    Scranton, Pa
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Combining Two Excel Macros

    Thank you vey much!

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Combining Two Excel Macros

    I've only a slight change as I can't replicate the errors you are receiving. If this doesn't resolve your issues then upload a dummy workbook.

    Instructions for attaching a sample workbook:
    Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    07-19-2013
    Location
    Scranton, Pa
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Combining Two Excel Macros

    I solved my problem by disabling the double click feature. Thanks for all your help!

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Combining Two Excel Macros

    Glad it all worked out. If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macros - Excel - Combining Sheets
    By HNoel33 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2013, 09:05 AM
  2. Combining two macros.
    By TERRI LEE in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2012, 03:56 AM
  3. MACROS for combining .CSV to XLS...
    By pma101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2011, 11:16 AM
  4. combining Macros
    By xcelwannabee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2009, 09:02 PM
  5. Combining Excel Macros (Excel 2007)
    By desware in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2008, 11:11 PM

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