Wrong Display in Worksheet Cells through ClassModule of Comman AllTextBoxes_change Event

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
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
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:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello

PFA
https://www.dropbox.com/s/o3xg1hr3leu9ze0/ClsAllTxtbxsChangeEvent.xlsm?dl=0

The above attached is completely different from the code in Post #1 . You may completely igonre the code posted #1

Would request (Anyone) to update the code with file name changed.

Have one common Textbox change event to change the value of cell in worksheet through Textbox and ready for next record entry to update the next cell value.
How can i achieve the same

thanks and Regards
NimishK
 
Upvote 0
My 2nd Attempt. All together new file
Attached file : https://www.dropbox.com/s/0tt04snvl7t2k6a/ClsAllTxtbxsChangeEvent-Rev1.xlsm?dl=0

Also added Std. Module in above new file for Globally and Publicly share varaibles
Overview
Form is loaded with all the cells value in the range from A2 to E13 to read the values of Row 2 in respective textboxes ie from textbox1 to textbox5
Able to see all the 5 cell values from A2 to E2 of 1st row in respective 5 textboxes.
Able to change the only Cell Value A2 with textbox1.value at run time with Change_Event , and when clicked next button. the changed value displayed in Cell A2 remains intact
this happens only in column A cells from Row 3 to Row 13.
Even if you dont change the value of Cell A2 from Textbox1.text the original value remains intact in textbox1 and cell A2 .when pressed the Next button and you are able to see the orignal value of A3 in Textbox1

I dont understand with above same effect for Columns from B to E and from Rows 2 to 13 its Not Happening :banghead::banghead:

Textboxes from textbox2 to textbox5 able to trigger change event. Able to change cell values From B2 to E2 through respective textboxes
but when next button clicked of Row 2 from columns B to E ie cells B2 to E2 the values of from B2 to E2 are repeated in B3 to E3 also same is seen in respective textbox2 to textbox5. Really dont understand whats happening. So my original data in from column B3 to E3 does not remain the same

IF everything happens for Column A correctly then why does not it happen for column B to E through respective textboxes

I've also added sheet 2 with same range and same cell values incase one misses something can copy the data as is from sheet2 to sheet1

Your Inputs to correct will be appreciated

NimishK
 
Last edited:
Upvote 0
Has Anyone tried according in Post #3 . ? with file attached
I am really Stuck
I dont understand with above same effect for Columns from B to E and from Rows 2 to 13 its Not Happening :banghead::banghead:

Textboxes from textbox2 to textbox5 able to trigger change event. Able to change cell values From B2 to E2 through respective textboxes
but when next button clicked of Row 2 from columns B to E ie cells B2 to E2 the values of from B2 to E2 are repeated in B3 to E3 also same is seen in respective textbox2 to textbox5. Really dont understand whats happening. So my original data in from column B3 to E3 does not remain the same

IF everything happens for Column A correctly then why does not it happen for column B to E through respective textboxes
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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