Sorry Roy, I should have read the rules first!
Yongle thanks so much for taking the time with this - it works perfectly now
Sorry Roy, I should have read the rules first!
Yongle thanks so much for taking the time with this - it works perfectly now
Thanks Yongle
So to further explain - the strFind is a combobox list of Criteria populated by the user on another userform. It then asks the user to select how may sub-criteria they would like to enter and depending on the number, a row of x number of 3 textboxes are created (sub-criteria title, min marks, max marks) which are to be written to the worksheet adjacent to the chosen criteria. For example:
Criteria | Min Marks | Max Marks | Sub-Criteria | Min Marks | Max Marks | Sub-Criteria | Min Marks | Max Marks |
C1 | 100 | 200 | SBC1 | 50 | 100 | SBC2 | 50 | 100 |
What's happening when I run the code is:
Criteria | Min Makrs | Max Marks | Sub-Criteria | Min Marks | Max Marks | Sub-Criteria | Min Marks | Max Marks |
C1 | 100 | 200 | SBC2 | 50 | 100 |
I did edited the code to reflect what you had written above but it's the same thing that's happening
Thanks so much for replying Yongle
I did as you suggested (I hope) but it is still just pulling in the data from the last row of textboxes?
Private Sub CommandButton1_Click()
'Finds criteria selected from Combobox in range(column 1) and populates last 3 empty columns in that row with data from textboxes created
Dim c As Range
Dim strFind As String
Dim lastcol As Long
strFind = ComboBox1.Value
Dim firstAddress As String
Dim p, j As Long
For p = 1 To number
With ThisWorkbook.Worksheets("Award_Criteria_Value").Range("A1:A100")
Set c = .Find(what:=strFind, After:=.Cells(.Rows.Count, 1), LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Debug.Print p, c.Address(0, 0)
lastcol = c.Cells(p, Columns.Count).End(xlToLeft).Column
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(0, lastcol).Value = Controls("TB1" & p).Text
c.Offset(0, lastcol + 1).Value = Controls("TB2" & p).Text
c.Offset(0, lastcol + 2).Value = Controls("TB3" & p).Text
Set c = .FindNext(c)
Loop While c.Address <> firstAddress
End If
End With
Next p
'Calls Clear_Form() sub
Clear_Form
End Sub
Display More
Hi,
Hope you can help me!
I'm trying to find a value in a range that matches combobox selection and then adds the value from a row of 3 textboxes to the last empty columns on that row. When I populate the textboxes (lets say I have two rows of dynamically created textboxes), it only takes the data from the last row I entered
Here's the code:
Dim c As Range
Dim strFind As String
Dim lastcol As Long
strFind = ComboBox1.Value
Dim p, j As Long
For p = 1 To number
With ThisWorkbook.Worksheets("xx").Range("A1:A100")
Set c = .Find(what:=strFind, After:=.Cells(.Rows.Count, 1), LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
lastcol = c.Cells(p, Columns.Count).End(xlToLeft).Column
If Not c Is Nothing Then
c.Offset(0, lastcol).Value = Controls("TB1" & p).Text
c.Offset(0, lastcol + 1).Value = Controls("TB2" & p).Text
c.Offset(0, lastcol + 2).Value = Controls("TB3" & p).Text
End If
End With
Next p
Display More