'How to change value of iRow depending on object value?
I am looking for the iRow value to be dependent on whether the object value.
I have 2 buttons:
Private Sub OptionButton1_Click()
End Sub
and
Private Sub OptionButton2_Click()
    
End Sub
If the value of button 1 is True I would like for iRow value to be 2 - for example. If the value of button 2 is True value would be 3 - for example.
I have tried the below code but it does not seem to work
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
    iRow = 2
Main code where iRow would need to be dependent on button value.
Private Sub TextBox1_AfterUpdate()
    Debug.Print ">AfterUpdate"
    Dim ws As Worksheet
    Dim iRow As Integer
    Dim iCol As Integer
    Dim sDate As String
    Dim oRange As Range
    Set oRange = Nothing
 
  
       
    Set ws = Worksheets.Item("Sheet1")
    sDate = Format(Now(), "dd/mm/yyyy")
    Debug.Print sDate, ws.Name
    Set oRange = ws.Range("A:A").Find(DateValue(sDate), , xlValues)
   
              
        If Not (oRange Is Nothing) Then
        iRow = oRange.Row
        iCol = 3
        ws.Cells(iRow, iCol).Formula = TextBox1.Value
        Debug.Print Now(), iRow, iCol, TextBox1.Value
    End If
       
End Sub
Can anyone please help?
Solution 1:[1]
Following proposal to solve the issue. In the Subs OptionButton1_Click()/OptionButton2_Click() rename the Variable, call it differently as the variable you use to check if you are in the correct row in reference to the date. Lets say the variable is called xRow.
Private Sub OptionButton1_Click()
     If OptionButton1.Value = True Then
     xRow = 1
To make it available in all other Subs, you need to declare it as global/public. Therefore add into a Module, not in the Code of the forms, following line at the top:
Public xRow As Integer
Finally, just modify your TextBox1_AfterUpdate():
..
        If Not (oRange.Row = iRow + xRow) Then
        iRow = oRange.Row + xRow
Note: the xRow is the row offset to the 1st found row date match. In the example OptionButton1_Click(), it would enter the input content one row below the 1st date match.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | DharmanBot | 
