+ Reply to Thread
Results 1 to 2 of 2

Update Range from User Form

  1. #1
    fybar
    Guest

    Update Range from User Form

    It seems that this shouldn't be too hard but I cannot figure it out. I
    select a range of cells that may have values or may be blank. I want to
    cycle through the cells and give the user a chance to accept the current
    value or enter their own. I have a user form with the following code:

    Private Sub UserForm_Initialize()
    Dim Puzzle As Range
    Dim temp As Range

    Set Puzzle = Sheets("Puzzle").Range("A1:P16")

    For Each temp In Puzzle
    'Highlight the cell to show the user where they are
    temp.Cells.Interior.ColorIndex = 6
    With UserForm2
    .StartUpPosition = 0
    .Top = 400
    .Left = 400
    .TextBox1.Text = temp.Value
    .TextBox1.SelStart = 0
    .TextBox1.SelLength = Len(.TextBox1.Text)
    .Show
    End With
    Next temp
    End Sub

    Private Sub CommandButton1_Click()
    'What to put in here?
    End Sub

    I had the Range setting code and For loop in the Sheet1 section and I got
    the loop to work. It would bring up a form and show the value and I would
    cycle through the forms by closing them with the X. Now, I moved this to
    the userform as I thought it would need to be there to get a value from the
    user to update the cell. How do I cycle through the range and accept or
    change values by hitting the Enter button? Also, I want to just use one
    form to do this, it seems more sensible.

    Is there a better or more acceptable way to do this?

    Thanks,

    fybar

  2. #2
    fybar
    Guest

    Re: Update Range from User Form

    On Sat, 01 Apr 2006 21:50:21 GMT, fybar wrote:

    > I had the Range setting code and For loop in the Sheet1 section and I got
    > the loop to work. It would bring up a form and show the value and I would
    > cycle through the forms by closing them with the X. Now, I moved this to
    > the userform as I thought it would need to be there to get a value from the
    > user to update the cell. How do I cycle through the range and accept or
    > change values by hitting the Enter button? Also, I want to just use one
    > form to do this, it seems more sensible.
    >
    > Is there a better or more acceptable way to do this?


    Ok, following up on my own post. I figured out how to do this. In the
    Sheet1 code area I have this for a button on the sheet:
    Private Sub cmdClearPuzzle_Click()
    UserForm2.Show
    Dim Puzzle As Range
    Dim temp As Range

    Set Puzzle = Sheets("Puzzle").Range("A1:P16")
    For Each temp In Puzzle
    temp.Cells.Interior.ColorIndex = 6
    temp.Cells.Activate
    With UserForm2
    .StartUpPosition = 0
    .Top = 400
    .Left = 400
    .TextBox1.Text = temp.Cells.Value
    .TextBox1.SelStart = 0
    .TextBox1.SelLength = Len(.TextBox1.Text)
    .Show
    End With
    Next temp

    End Sub

    And in the userform code area:

    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
    Shift As Integer)
    If KeyCode = 13 Then
    ActiveCell.Value = Me.TextBox1.Value
    ActiveCell.Interior.ColorIndex = 0
    Me.Hide
    End If

    End Sub

    This works exactly as I want it to. Does this seem like the best way to
    accomplish this? If anyone has any suggestion I would welcome them.

    Thanks,

    fybar

+ 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