Hello
There is wrong Display in Worksheet Cells through ClassModule of Comman AllTextBoxes_change Event
The range is from D2 to E25 .
Want common change event for textboxes when typed in textboxes should change simultaneoulsy in rescpective cells of columns D and E. and when Next button clicked ready to enter the next record in textboxes which will also display its value in respective cells of that row
What happens is when Next Button clicked the value of next Row D cell in Textbox4.text is displayed in previous Row simlair with Cell E with Textbox5.text. I know this is because of common change event that is coded . How can i control this so that when current value changed in Textbox4.text and Textbox5.text which is also displayed in respective row of sheet simultaneously
and When next button is clicked am prepared to enter the Next record in respective text box and values of Cell D and Cell E of that row is displayed on Worksheet as changing in textboxes.
I've just coded only for now Two textboxes . Wanted to try with common change event as trying it for First time. Also your guidance on passing comman variables for Class Module and Userform will be really appreciable
Code Below:
In Class Module
Name of Class Module = Class_AllTextBoxes
'In userform
Thanks and Regards
NimishK
There is wrong Display in Worksheet Cells through ClassModule of Comman AllTextBoxes_change Event
The range is from D2 to E25 .
Want common change event for textboxes when typed in textboxes should change simultaneoulsy in rescpective cells of columns D and E. and when Next button clicked ready to enter the next record in textboxes which will also display its value in respective cells of that row
What happens is when Next Button clicked the value of next Row D cell in Textbox4.text is displayed in previous Row simlair with Cell E with Textbox5.text. I know this is because of common change event that is coded . How can i control this so that when current value changed in Textbox4.text and Textbox5.text which is also displayed in respective row of sheet simultaneously
and When next button is clicked am prepared to enter the Next record in respective text box and values of Cell D and Cell E of that row is displayed on Worksheet as changing in textboxes.
I've just coded only for now Two textboxes . Wanted to try with common change event as trying it for First time. Also your guidance on passing comman variables for Class Module and Userform will be really appreciable
Code Below:
In Class Module
Name of Class Module = Class_AllTextBoxes
Code:
Option Explicit
Public WithEvents AllTextbox As MSForms.TextBox
Public WithEvents AllComboBox As MSForms.ComboBox
Public curRowRange As Long
Public FirstMinRow As Long
Public curRec As Integer
Public nosofRows As Long
Public RgsWs As Worksheet
Dim x As Long, y As Long
Private Sub AllTextBox_Change()
curRec = 1
Set RgsWs = Worksheets("Sheet1")
curRowRange = Sheet1.Range("D2:E25").Rows(curRec).Row
RgsWs.Range("D" & curRowRange).Value = UserForm1.TextBox4.Value
RgsWs.Range("E" & curRowRange).Value = UserForm1.TextBox5.Value
End Sub
'--------------------
'In userform
Code:
Option Explicit
Public curRowRange As Long
Public FirstMinRow As Long
Public curRec As Integer
Public nosofRows As Long
Public AllTextboxes As Collection
Private Sub UserForm_Initialize()
curRec = 1
Dim RowNumber As Long
Dim lstSelRow As Long
Dim nosRows As Long
Dim FirstMinRow As Long
nosRows = Sheet1.Range("D2:E25").Rows.Count
FirstMinRow = Sheet1.Range("D2:E25").Rows.Row
TextBox2.Text = nosRows
TextBox3.Text = FirstMinRow
TextBox4.Text = Sheet1.Cells(FirstMinRow, 4).Value
TextBox5.Text = Sheet1.Cells(FirstMinRow, 5).Value
Dim oneTextBox As Variant
Dim allTxtBxes As Class_AllTextboxes
Set AllTextboxes = New Collection
For Each oneTextBox In UserForm1.Controls
If TypeName(oneTextBox) = "TextBox" Then
Set allTxtBxes = New Class_AllTextboxes
Set allTxtBxes.AllTextbox = oneTextBox
AllTextboxes.Add Item:=allTxtBxes, Key:=oneTextBox.Name
End If
Next oneTextBox
Set allTxtBxes = Nothing
End Sub
Private Sub commandNextRec_Click()
ReDim d$(1 To aRow)
ReDim e$(1 To aRow)
If curRec < 25
curRowRange = Sheet1.Range("D2:E25").Rows(curRec).Row
d$(curRec) = TextBox4.Text
e$(curRec) = TextBox5.Text
Worksheets("Sheet1").Cells(curRowRange, "D").Value = d$(curRec)
Worksheets("Sheet1").Cells(curRowRange, "E").Value = e$(curRec)
curRec = curRec + 1
curRowRange = curRowRange + 1
lblSrNo2.Caption = Format$(curRec)
TextBox4.Text = Sheet1.Cells(curRowRange, 4).Value
TextBox5.Text = Sheet1.Cells(curRowRange, 5).Value
End If
End if
End Sub
Thanks and Regards
NimishK
Last edited: