populate date in textbox based on fill next adjacent textbox by two loop

Mussa

Active Member
Joined
Jul 12, 2021
Messages
264
Office Version
  1. 2019
  2. 2010
I have multiple textboxes (textbox 61:textbox 124) and (textbox 62:textbox 125) . what I want when fill any textbox from 62:125 should populate date (today ) from 61:124 based on adjacent textbox for each textbox is filled from 62:125
I try doing two loops but doesn't success so far
VBA Code:
Sub pop_date()
 Dim i, S As Long
    For i = 62 To 125 Step 7
        'first set of TextBoxes
        If Me.Controls("TextBox" & i) <> "" Then
        
        For i = 61 To 124 Step 7
        With Me.Controls("TextBox" & S)
            .Value = Format(.Value, "DD/mm/YYYY")
        End With
    Next i
    Next S
End Sub
thanks in advance .
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I don't know how to solve you problem, but 2 things jump out at me with your code.

1) You have 2 loops with 'i' as the counter. Neither of them loop with 'S'
VBA Code:
For i = 62 To 125 Step 7
For i = 61 To 124 Step 7


2) The is no End If for the If statement. I am surprised you did not get a compile error.
 
Upvote 0
I am surprised you did not get a compile error.
yes it's really show but I don't mention so, sorry !
thanks for your important notices, but unfortunately doesn't work as what I want it .
here is the code after fixing some syntax.
VBA Code:
Sub pop_date()
 Dim i, S As Long
    For i = 67 To 137 Step 7
        'first set of TextBoxes
        If Me.Controls("TextBox" & i) <> "" Then
      
        For S = 66 To 136 Step 7
        With Me.Controls("TextBox" & S)
            .Value = Format(DATE, "yyyy/mm/dd")
        End With
        'second set of TExtBoxes
        Next S
       End If
    Next i
  
End Sub
it will populate date for all of textboxes (66:137) even if next adjacent textbox is empty !
 
Last edited:
Upvote 0
Again, this is way out of my knowledge. But try this. If it doesn't work, someone else will have to help.

VBA Code:
Sub pop_date()
 Dim i, S As Long
    For i = 67 To 137 Step 7
        'first set of TextBoxes
        If ActiveSheet.OLEObjects("TextBox" & i).Object.Value <> "" Then
      
        For S = 66 To 136 Step 7
        ActiveSheet.OLEObjects("TextBox" & S).Object.Value = Format(DATE, "yyyy/mm/dd")
        
        'second set of TExtBoxes
        Next S
       End If
    Next i
  
End Sub
 
Upvote 0
Thanks
The same thing populate date for all of textboxes even adjacent textboxes are empty.
 
Upvote 0
BTW: you use textbox inside the sheet, but I'm talking about on userform as in OP
anyway thank you ;)
so I wait for another body if there is chance to solve my problem .🙏
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top