The form in question works as follows:
User will put in a ID number, hit FIND, and then the form will populate with Opportunity Names and Opportunity $Amounts for each match of the ID found from another workbook.
The User then hits POPULATE and the form matches the ID, Name, and $Amount, to the 2nd workbook and copies values from the 2nd workbook and place them in the original workbook that holds the form.
If the $Amount is TEXT in the 2nd workbook, I can get the 3 matches to work and it will copy the values. However, if it is in CURRENCY, as it currently is, it does not see the three values as matching and stops the routine.
I can make the $Amount textbox (textbox3) into currency using this:
Private Sub TextBox_AfterUpdate()
With TextBox3
.Value = Format(.Value, "currency")
End With
End Sub
and then calling it in the FIND routine before the end sub command.
That formats the texbox in the form as a currency, but then when it tries and matches it still can't seem to recognize and run. Below is the code for the Find procedure, and then the Populate procedure.
I was considering running a looped command that converted the Currency values in the 2nd workbook to TEXT, but would really prefer to leave as is. Does anyone have any ideas to make the code work as it is?
FIND
Private Sub CommandButton2_Click()
Dim s1 As String
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim s2 As String
Dim StartRow As Long
Dim LastRow As Long
Dim match_found As Boolean
Dim i As Long
s1 = "Report Southern - Current Quart"
match_found = False
On Error Resume Next
Set ws = Workbooks("Report Southern - Current Quarter R-Matrix.xls").Worksheets(s1)
On Error GoTo 0
If ws Is Nothing Then
MsgBox "Either Report Southern - Current Quarter R-Matrix.xls is not open, or else it does not contain " & s1 & _
vbCrLf & "Terminating", _
vbCritical, "ERROR"
Exit Sub
End If
StartRow = 4
LastRow = ws.UsedRange.Rows.Count
For i = StartRow To LastRow
If ws.Cells(i, 1) = TextBox1 Then
match_found = True
TextBox2 = ws.Cells(i, 3)
TextBox3 = ws.Cells(i, 4)
If ws.Cells(i + 1, 1) = TextBox1 Then
TextBox4 = ws.Cells(i + 1, 3)
TextBox5 = ws.Cells(i + 1, 4)
End If
If ws.Cells(i + 2, 1) = TextBox1 Then
TextBox6 = ws.Cells(i + 2, 3)
TextBox7 = ws.Cells(i + 2, 4)
End If
Exit For
End If
Next i
If Not match_found Then
TextBox2 = "Sorry that ID does not match"
End If
On Error Resume Next
With Workbooks("R Deal Summary w Macros with color mods.xls")
.Activate
.Worksheets("PreR1 CM").Select
End With
On Error GoTo 0
TextBox_AfterUpdate
End Sub
POPULATE
Private Sub CommandButton4_Click()
Dim s1 As String
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim s2 As String
Dim StartRow As Long
Dim LastRow As Long
Dim match_found As Boolean
Dim i As Long
s1 = "Report Southern - Current Quart"
s2 = "PreR1 CM"
match_found = False
On Error Resume Next
Set ws = Workbooks("Report Southern - Current Quarter R-Matrix.xls").Worksheets(s1)
Set ws2 = Workbooks("R Deal Summary w Macros with color mods.xls").Worksheets(s2)
On Error GoTo 0
If ws Is Nothing Then
MsgBox "Either Report Southern - Current Quarter updated.xls is not open, or else it does not contain " & s1 & _
vbCrLf & "Terminating", _
vbCritical, "ERROR"
Exit Sub
End If
StartRow = 4
LastRow = ws.UsedRange.Rows.Count
For i = StartRow To LastRow
If ws.Cells(i, 1) = TextBox1 And ws.Cells(i, 3) = TextBox2 And ws.Cells(i, 4) = TextBox3 Then
match_found = True
ws2.Cells(6, 3) = ws.Cells(i, 1)
ws2.Cells(7, 3) = ws.Cells(i, 3)
ws2.Cells(8, 3) = ws.Cells(i, 4)
ws2.Cells(9, 3) = ws.Cells(i, 5)
ws2.Cells(18, 3) = ws.Cells(i, 6)
ws2.Cells(19, 3) = ws.Cells(i, 20)
ws2.Cells(21, 3) = ws.Cells(i, 7)
ws2.Cells(6, 6) = ws.Cells(i, 8)
ws2.Cells(7, 6) = ws.Cells(i, 9)
ws2.Cells(8, 6) = ws.Cells(i, 10)
ws2.Cells(9, 6) = Application.WorksheetFunction.Days360(ws2.Cells(8, 6), ws.Cells(i, 11))
ws2.Cells(14, 6) = ws.Cells(i, 12)
ws2.Cells(15, 6) = ws.Cells(i, 13)
ws2.Cells(16, 6) = ws.Cells(i, 14) & " , " & ws.Cells(i, 15)
ws2.Cells(17, 6) = ws.Cells(i, 17)
ws2.Cells(18, 6) = ws.Cells(i, 16)
ws2.Cells(6, 13) = ws.Cells(i, 18)
ws2.Cells(9, 13) = ws.Cells(i, 19)
ws2.Cells(9, 14) = ws.Cells(i, 22)
ws2.Cells(9, 16) = ws.Cells(i, 23)
ws2.Cells(9, 17) = ws.Cells(i, 20)
Exit For
End If
Next i
On Error Resume Next
With Workbooks("R Deal Summary w Macros with color mods.xls")
.Activate
.Worksheets("PreR1 CM").Select
End With
On Error GoTo 0
End Sub
Bookmarks