View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Martin Fishlock[_4_] Martin Fishlock[_4_] is offline
external usenet poster
 
Posts: 32
Default Updating multiple worksheets dependent on checkbox selection

Andy

From what I underatand you want to update different worksheets based on the
values of the user dialog.

One way to do it is when the usrr clicks the 'ok' or 'do it' button that you
check the status of the check boxes and update the variable accordingly, you
then use the variable to update the data as in:
'---------
dim sz_sheetname as string
sz_sheetname = "the name of the sheet"
activeworkbook.worksheets(sz_sheetname).range("A1" ) = "what ever!"
'----------
You then have to decide on how to maintain the list of links and I prefer to
have a datasheet in the macro book where all the data is and I would use the
following.
'----------
Private Sub CommandButton1_Click()
Dim sz_worksheet_to_use As String
If IsNull(Me.CheckBox1) Then Me.CheckBox1.Value = False
If Me.CheckBox1.Value = True Then
ThisWorkbook.Worksheets("Data").Range("B2") = "SheetCheck1"
Else
ThisWorkbook.Worksheets("Data").Range("B2") = "SheetNotCheck1"
End If
sz_worksheet_to_use = ThisWorkbook.Worksheets("Data").Range("B2")
ActiveWorkbook.Worksheets(sz_worksheet_to_use).Ran ge("A1") = "Some value"
thisworkbook.Save ' save the updated reference
End Sub

'----------
Here I have a workbook with two worksheets in it called SheetCheck1 and
SheetNotCheck1 and the data sheet in the macrobook.

With this approach I can load the default values when I load the form with:

Private Sub UserForm_Initialize()
If ThisWorkbook.Worksheets("Data").Range("B2") = "SheetCheck1" Then
Me.CheckBox1.Value = True
ElseIf ThisWorkbook.Worksheets("Data").Range("B2") = "SheetNotCheck1" Then
Me.CheckBox1.Value = False
End If
End Sub

Note that activeworkbook is the workbook where you called the macro from and
thisworkbook is the workbook where the macro and form is save in.

Hope this is clear.
--
HTHs Martin


"andymcgooner" wrote:

Hi All,

I am hoping one of you guys can help.

I have a userform with multiple textboxes etc that i want to transfer
to a workbook containing numerous sheets. I can do it if it is to one
sheet but some of the information is dependant on the outcome of
checkboxes etc. In addition to this i am using checkboxes to determine
which worksheets get the information loaded.

I did think that if i set the sheet name used in the main procedure as
a variable and have this set from the state of the checkboxes, but i
just cant seem to get the variables right and get errors.

Any help would be greatly appreciated!

Andy