Thread: UserForm Issues
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Maria Maria is offline
external usenet poster
 
Posts: 71
Default UserForm Issues

Hello Tom:

Sorry - I know what the issue is -- I have cell D41 Protected.

This brings another question. Can I use VBA to unprotect the sheet, write
in the response to D41 and then protect the sheet again?

Thank you for all your help
Maria


"Maria" wrote:

Tom

Thank you - it did work for a couple of hours. Now I am getting an error
message for the following line:

ThisWorkbook.ActiveSheet.Range("D41").Value = Range("D39") * 0.16

Is there another method of referencing the cell D41?
Or I am wondering if maybe I have not declared the workbook right. The
following code is in my Workbook_Open declaration:

Private Sub Workbook_Open()
'this automatically opens the UserForm when the excel workbook is opened
FormIVA.Show

End Sub






ThisWorkbook.ActiveSheet.Range("D41").Value = Range("D39") * 0.16


"Tom German" wrote:

Maria,

Here are two ways that may work for you. Note: "Me" represents the userform
where the code block is located.

Private Sub ButtonOK_Click()
'''Determine which optionbutton is selected.
If Me.OpBtnIVA.Value = True Then
ThisWorkbook.ActiveSheet.Range("D41").Value = Range("D39") * 0.16
Unload FormIVA
ElseIf Me.OpBtnIVAExento.Value = True Then
ThisWorkbook.ActiveSheet.Range("D41").Value = "EXENTO"
Unload FormIVA
Else
MsgBox "Please select one of the options"
End If
End Sub


-- OR --


Private Sub ButtonOK_Click()
'''Determine which optionbutton is selected.
Select Case True
Case Me.OpBtnIVA.Value
ThisWorkbook.ActiveSheet.Range("D41").Value = Range("D39") * 0.16
Unload FormIVA
Case Me.OpBtnIVAExento.Value
ThisWorkbook.ActiveSheet.Range("D41").Value = "EXENTO"
Unload FormIVA
Case Else
MsgBox "Please select one of the options"
End Select
End Sub


"Maria" wrote in message
...
Hello - I am new to programming in VB - I am using Excel 2003. I am
mostly
reading some Excel help books and Searching on the internet for example
code.

Characteristics of userform:
- I have a UserForm that displays properly when excuting the Macro in the
Workbook (which only has 1 worksheet)
- I have only 2 Option Buttons set in a Frame -- the values CAN be
selected
(one at a time) -- Option Button Names: OpBtnIVA, OpBtnIVAExento
- I have an OK button - which is NOT working properly - I get an error of
"1004" when clicked -- Button Name: ButtonOK
- I also have code for the UserForm Cancel Control - which IS working
properly.

Results Expected:
1. When selecting OpBtnIVA then Cell D41 will be populated with D39*0.16
(computed value)
Note: D41 is a combined range of cells (D41, D42, E41 and E42) but when
selecting the range (in Excel) the cell is listed as D41.
2. When selecting OpBtnIVAExento then Cell D41 will be populated with the
text EXENTO
Note: D39 is a combined range of cells (D39, D40, E39 and E40) but when
selecting the range (in Excel) the cell is listed as D39

I have tried the following 2 codes in my button but either code is not
functioning.

1st Button Code:

Private Sub ButtonOK_Click()

Dim x As Control

For Each x In Frame1.Controls
If x.Value = "OpBtnIVA" Then
Range("D41").Value = Range("D39") * 0.16
Unload FormIVA

ElseIf x.Value = "OpBtnIVAExento" Then
Range("D41").Value = "EXENTO"
Unload FormIVA

End If
Next

End Sub


2nd Button Code:

Private Sub ButtonOK_Click()

If OpBtnIVA Then Cells(41, D).Value = Cells(39, D).Value * 0.16
If OpBtnIVAExento Then Cells(41, D).Value = "EXENTO"
Unload FormIVA

End Sub

If you need anything else, please indicate. All help is greatly
appreciated.

thank you in advance
Maria