Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2016, 09:13 PM
wlcdo2 wlcdo2 is offline Update Cell in a Table with Value from User Form Windows 7 32bit Update Cell in a Table with Value from User Form Office 2013
Novice
Update Cell in a Table with Value from User Form
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default Update Cell in a Table with Value from User Form

I have a table within Word 2013 document. I want the user to select any cell within that table to be the 'recipient' of a value from a User Form. The user then opens the User Form that displays various choices by way of OptionButtons i.e. they may select from values such as A0, A3, A5, C5. Once they have made their choice, I have an "Update" button that transfers the value of the OptionButton to the cell in the table. I tried by inserting a Bookmark into the table, like so:

Code:
Private Sub btnUpdateP_Click()

Dim PeopleChoice As String, Tbl As Table, Rng As Range

If Me.optA0 Then
    PeopleChoice = "A0"
ElseIf Me.optA3 Then
    PeopleChoice = "A3"
ElseIf Me.optA5 Then
    PeopleChoice = "A5"
Else
    PeopleChoice = "C5"
End If
    Selection.Bookmarks.Add ("bmPeople")
    ActiveDocument.Bookmarks("bmPeople").Select
    Selection.Text = PeopleChoice
When I run through the code using the debugger, it works fine, but when I run the code for real (using an ActiveX button), the Bookmark is inserted at the location of the button that calls the UserForm, instead of the Table Cell.

Can anyone assist me with this one please?

Thank you.

Corin.
Reply With Quote
  #2  
Old 06-20-2016, 02:54 AM
macropod's Avatar
macropod macropod is online now Update Cell in a Table with Value from User Form Windows 7 64bit Update Cell in a Table with Value from User Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by wlcdo2 View Post
When I run through the code using the debugger, it works fine, but when I run the code for real (using an ActiveX button), the Bookmark is inserted at the location of the button that calls the UserForm, instead of the Table Cell.
That's because clicking on the ActiveX button changes the selection. You might do better to have your userform solicit the cell address to work with. Do note that Word VBA doesn't use A1 referencing so, if you solicit that, your code will need to transform it into rowindex & columnindex referencing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-21-2016, 12:00 PM
wlcdo2 wlcdo2 is offline Update Cell in a Table with Value from User Form Windows 7 32bit Update Cell in a Table with Value from User Form Office 2013
Novice
Update Cell in a Table with Value from User Form
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default

Thanks for the reply Paul. I'm still a little stuck on the correct coding. The Row and column Index I understand, but I'm still stuck on the rest of the VBA to get the user form to solicit the cell address. Would you be able to share some sample code at all to help me in the right direction?
Thx.
Reply With Quote
  #4  
Old 06-21-2016, 04:55 PM
macropod's Avatar
macropod macropod is online now Update Cell in a Table with Value from User Form Windows 7 64bit Update Cell in a Table with Value from User Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code depends on what you want the user to input - something like 'A10' in a single textbox or '1' for the column in one textbox and '10' for the column in another. Which approach are you using?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-21-2016, 08:53 PM
wlcdo2 wlcdo2 is offline Update Cell in a Table with Value from User Form Windows 7 32bit Update Cell in a Table with Value from User Form Office 2013
Novice
Update Cell in a Table with Value from User Form
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default

Hi Paul,
In the context of the document, what I've got is a Work Method Statement / Job Safety Analysis whereby each line of the table is a chronological step of how an activity or project will be completed safely. Part of the work analysis is determining hazards for each step by referring to a Risk Assessment Matrix. I'm hoping to simplify completion of the WMS / JSA whereby the user displays the Risk Assessment Matrix (which was my UserForm) and simply clicks the relevant hazard rating from that UserForm; in this case I was utilising Option Buttons for each type of hazard rating i.e. A0, A3, C5.
The result from the selected OptionButton would then populate the cell of the table they had clicked in to.

Does this help describe what I'm hoping to achieve? Would some additional screen shots help perhaps?

Thank you.
Reply With Quote
  #6  
Old 06-21-2016, 09:16 PM
gmayor's Avatar
gmayor gmayor is offline Update Cell in a Table with Value from User Form Windows 10 Update Cell in a Table with Value from User Form Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If instead of using an ActiveX button, which, as Paul says, becomes the selection when you click it, you were to use a ribbon button to call the userform, you wouldn't have this problem, as the selection would remain in the table cell.

With an ActiveX button you would have to add the means of indicating to the macro which cell to process. This could, for example take the form of a pair of combo-boxes to indicate the row and column respectively. This works as long as there are no split or merged cells.

You can then refer to the selection in these boxes and create a range to the corresponding cell. e.g. as follows

Code:
Option Explicit
Private Sub UserForm_Initialize()
Dim oTable As Table
Dim i As Integer
    Set oTable = ActiveDocument.Tables(1)
    With Me.ComboRow
        For i = 1 To oTable.Rows.Count
            .AddItem i
        Next i
        .ListIndex = 0
    End With
    With Me.ComboColumn
        For i = 1 To oTable.Columns.Count
            .AddItem i
        Next i
        .ListIndex = 0
    End With
End Sub


Private Sub btnUpdateP_Click()
Dim oTable As Table
Dim oCell As Range
Dim PeopleChoice As String
Dim iRow As Integer, iCol As Integer
    Set oTable = ActiveDocument.Tables(1)
    iRow = Me.ComboRow.ListIndex + 1
    iCol = Me.ComboColumn.ListIndex + 1
    
    Select Case True
        Case Is = Me.optA0.Value: PeopleChoice = "A0"
        Case Is = Me.optA3.Value: PeopleChoice = "A3"
        Case Is = Me.optA5.Value: PeopleChoice = "A5"
        Case Else: PeopleChoice = "C5"
    End Select
    Me.Hide
    Set oCell = oTable.Rows(iRow).Cells(iCol).Range
    oCell.End = oCell.End - 1
    oCell.Text = PeopleChoice
    Unload Me
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 06-21-2016, 10:12 PM
macropod's Avatar
macropod macropod is online now Update Cell in a Table with Value from User Form Windows 7 64bit Update Cell in a Table with Value from User Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Another option would be to use a modeless userform, so the cell could be selected after the userform is activated.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 06-23-2016, 04:04 PM
wlcdo2 wlcdo2 is offline Update Cell in a Table with Value from User Form Windows 7 32bit Update Cell in a Table with Value from User Form Office 2013
Novice
Update Cell in a Table with Value from User Form
 
Join Date: Jun 2016
Posts: 17
wlcdo2 is on a distinguished road
Default

Thanks so much Paul and Graham. I ended up using a combination of the modeless userform and making the TakeFocusOnClick property of the form call button to False which has solved my query.
Thanks again for all your valuable feedback and direction; much appreciated.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Cell in a Table with Value from User Form Allow Multiple Content Control same cell of form table DeborahBartlett Word 1 01-04-2014 11:06 AM
Update Cell in a Table with Value from User Form Trying to update a table cell with a value based on a drop down box entry mkasem Word VBA 2 09-29-2013 08:36 PM
Update Cell in a Table with Value from User Form Text Form Fields - Filling the table cell simville02 Word Tables 1 01-31-2013 11:12 PM
Update Cell in a Table with Value from User Form Update Outlook but user path changed Ossie1972 Outlook 1 12-08-2010 08:19 PM
Text Wrapping on Fixed Lines in a Form field/Table cell okrmjr Word Tables 0 10-30-2009 08:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft