Consulting

Results 1 to 4 of 4

Thread: Edit Current Selected Cell

  1. #1
    VBAX Contributor
    Joined
    Jun 2015
    Location
    Houston
    Posts
    111
    Location

    Question Edit Current Selected Cell

    Greetings,


    I'm trying to add an edit function to my workbook. This is to allow the user to edit the Part Number on a list if the part they want for that system is wrong. There are multiple sheets with different amounts of data, but all these sheets are pulling their information from a "Master DataList" page.

    So what I need to do is provide the user an InputBox so they can edit the current selected cell. That cell can be any currently used cell in Column "C" on the worksheet, but the number of rows that covers will vary.

    I'm looking for samples, but not having much luck so far.

    Thanks.
    Thanks.

    Lord Dragon

    "Discovery consists not in seeking new lands, but in seeing with new eyes." ~ Marcel Proust

  2. #2
    VBAX Contributor
    Joined
    Jun 2015
    Location
    Houston
    Posts
    111
    Location
    Ok. I've come up with the following code (which doesn't work) as an example of what I'm trying to do.

    Sub EditSelection(control As IRibbonControl)
    
    Dim partInput As String
    
    
        With ActiveSheet
            If ActiveCell.Range = "C" Then
                ActiveCell.Select
                partInput = InputBox("Please enter the part number you want.", "Part Number Change")
                ActiveCell.FormulaR1C1 = partInput
            End If
    End Sub
    So the basic concept here is to make sure the selected cell is in Column C and within the range of use cells. (I'll be modifying the code slightly for the control that will let the user add new parts.) Then to pull up an Input Box they will use to enter the new part number.

    If possible, I would like the Input Box to populate with the current value of the selected cell, and/or of the Input Box is blank and they select "Ok" instead of "Cancel" then it doesn't change the cell value.

    Any help is appreciated.
    Thanks.

    Lord Dragon

    "Discovery consists not in seeking new lands, but in seeing with new eyes." ~ Marcel Proust

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Assuming that this is a callback to a CustomUI button

    Not tested, but maybe something along these lines


    Sub EditSelection(control As IRibbonControl) 
        Dim partInput As String 
         
        With ActiveSheet
            If Intersect(ActiveCell, .Columns(3)) Is Nothing Then Exit Sub
            If Intersect(ActiveCell, .UsedRange) Is Nothing Then Exit Sub
    
            partInput = InputBox("Please enter the part number you want.", "Part Number Change") 
    
           If Len(partInput) = 0 The Exit Sub
    
           ActiveCell.Value = partInput 
    
        End Sub
    ---------------------------------------------------------------------------------------------------------------------

    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

  4. #4
    VBAX Contributor
    Joined
    Jun 2015
    Location
    Houston
    Posts
    111
    Location
    There was a small typo here "If Len(partInput) = 0 The Exit Sub" (should be Then Exit Sub).

    And I had to add "End With" before End Sub.

    Otherwise this works great.

    Thanks a lot. I don't know why I couldn't figure this out.
    Thanks.

    Lord Dragon

    "Discovery consists not in seeking new lands, but in seeing with new eyes." ~ Marcel Proust

Posting Permissions

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