Consulting

Results 1 to 3 of 3

Thread: VBA to record value of a named range cell

  1. #1

    VBA to record value of a named range cell

    Hello,
    I am a bit rusty in my VBA and can't figure out what I'm doing wrong for what I think is a simple task.

    Sheet1 has a named range "EEName"
    Sheet2 is a listing of all the EEName that I want to record

    I need a macro that will record the value of what the user enters into the EEName named range in Sheet1 in column A of sheet 2 with each time the macro is run, the new record should be in the new blank row.

    meaning user enters "Sarah" and then runs the macro. Sheet2 cellA2 should record Sarah
    User then enters "John" and runs the macro. macro should find the next blank row in Sheet2 - which would be row 3 now (essentially counting the rows with a value in column A and adding 1) - and record John in cell A3

    I feel like this should be really simple, but it's been a few years since I've written VBA (or any coding) and I'm losing it.

    Assistance would be appreciated

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,837
    Location
    Try this, at least as a starting point

    In Sheet1 code module

    Option Explicit
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Cells(1, 1).Address = [EEName].Address Then Exit Sub
        
        sOldEEname = [EEName].Value
    '    Debug.Print Target.Cells(1, 1).Address & "---" & "Old Name = " & sOldEEname
    End Sub
    
    
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Cells(1, 1).Address <> [EEName].Address Then Exit Sub
        If Target.Cells(1, 1).Value = sOldEEname Then Exit Sub
        
        Application.EnableEvents = False
        With Worksheets("Sheet2")
            .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Value = Target.Cells(1, 1).Value
        End With
        Application.EnableEvents = True
        
    End Sub
    In standard module

    Option Explicit
    
    
    Public sOldEEname As String
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    thank you so much!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •