Suzanne Peel
New Member
Good Morning/Afternoon/Evening.....
I have a sort of "Catch-22" with opening a userform.
An excel spreadsheet contains the data I want to use. There are 170 odd columns in the spreadsheet so I created a userform to be able to update the spreadsheet in an easier manner.
The form is set up to populate from the spreadsheet - however when the textbox gets it value it triggers the textbox_Change event which runs the code I set up to be able to update the spreadsheet from the form, this in turn triggers the worksheet_Change event which updates the database connected to the spreadsheet.
So basically I copy the cell contents to the userform the userform detects a change and updates the spreadsheet with what it just received and the "change" gets sent to the database to update the data - even though there was no change in the first place .....
I need to determine the column numbers at execution because I don't want to be hardcoding the column numbers only to have to recode when I add or delete a column (which is common).
Any assistance will be gratefully received.
Suzy
I know my programming is awkward but here is the code-
I have a sort of "Catch-22" with opening a userform.
An excel spreadsheet contains the data I want to use. There are 170 odd columns in the spreadsheet so I created a userform to be able to update the spreadsheet in an easier manner.
The form is set up to populate from the spreadsheet - however when the textbox gets it value it triggers the textbox_Change event which runs the code I set up to be able to update the spreadsheet from the form, this in turn triggers the worksheet_Change event which updates the database connected to the spreadsheet.
So basically I copy the cell contents to the userform the userform detects a change and updates the spreadsheet with what it just received and the "change" gets sent to the database to update the data - even though there was no change in the first place .....
I need to determine the column numbers at execution because I don't want to be hardcoding the column numbers only to have to recode when I add or delete a column (which is common).
Any assistance will be gratefully received.
Suzy
I know my programming is awkward but here is the code-
Code:
Private Sub UserForm_Activate()
Dim ctl As Control
Dim ICOLUMN As Variant
Dim STRFILL As Variant
Dim CNAME As String
Dim rngToFind As Range
Dim i As Long
Call ManCalc
With Me
'This will create a vertical scrollbar
.ScrollBars = fmScrollBarsVertical
'Change the values of 2 as Per your requirements
.ScrollHeight = .InsideHeight * 1.5
.ScrollWidth = .InsideWidth * 9
End With
For Each ctl In Me.Controls
'If Left$(ctl.Name & "1234", 4) = "tbox" Then
If TypeOf ctl Is MSForms.TextBox Then
CNAME = Mid$(ctl.Name, 5, 20)
With ActiveSheet.Range("$2:$2") ' The cell hold the name of the Textbox
Set STRFILL = .Find(What:=CNAME, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With
If Not STRFILL Is Nothing Then 'Not nothing means SOMETHING found
ICOLUMN = STRFILL.Column
ctl.Text = ActiveSheet.Cells(ActiveCell.Row, ICOLUMN).Value
Else
'MsgBox error routine not essential.
MsgBox "Error! " & CNAME & " not found." & vbCrLf & _
"Processing terminated."
Call AutoCalc
Exit Sub
End If
End If
Next ctl
Call AutoCalc
End Sub
Private Sub tboxARno_Change()
Call All_changes
End Sub
Public Sub All_changes()
Dim CNAME As String
Dim STRFILL As Variant
Dim ICOLUMN As Integer
CNAME = Mid$(ActiveControl.Name, 5, 20)
With ActiveSheet.Range("$2:$2")
Set STRFILL = .Find(What:=CNAME, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With
ICOLUMN = STRFILL.Column
ActiveSheet.Cells(ActiveCell.Row, ICOLUMN).Value = ActiveControl.Text
End Sub
Last edited by a moderator: