ineedhelp1
New Member
- Joined
- Apr 22, 2015
- Messages
- 15
Hi
I have a data sheet layed out as follows:
<tbody>
</tbody>
My userform has the customer name on (that is currently selected on my front end sheet).
I have set the user form up so when I type a comment, it finds the said customer in my Data sheet and pastes the Date, Application User and Comment into the end of the correct line.
At the moment I am just using a VLOOKUP within VBA to find the customer name and return the values in columns 22, 23 and 24 (as these are the first entries - Data, App User and Comment1).
What I need is to return those 3 values and then when another comment is typed, it shows the 3 values (date, App user and Comment2) on a new line within the text box on my user form.
My code is as follows;
I have identified that due to the vlookup, it only returns my specified values, but I'm really struggling to figure out a way to almost return the first 3 cells of choice, then offset these to return the next 3 cell values on the row below
and so forth.
Please help!
I have a data sheet layed out as follows:
Customer A | Date | App User | Comment1 | Date | App User | Comment2 |
Customer B | Date | App User | Comment1 | Date | App User | Comment2 |
Customer C | Date | App User | Comment1 | Date | App User | Comment2 |
<tbody>
</tbody>
My userform has the customer name on (that is currently selected on my front end sheet).
I have set the user form up so when I type a comment, it finds the said customer in my Data sheet and pastes the Date, Application User and Comment into the end of the correct line.
At the moment I am just using a VLOOKUP within VBA to find the customer name and return the values in columns 22, 23 and 24 (as these are the first entries - Data, App User and Comment1).
What I need is to return those 3 values and then when another comment is typed, it shows the 3 values (date, App user and Comment2) on a new line within the text box on my user form.
My code is as follows;
Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim database As Worksheet
Dim data As Worksheet, rr As range
Dim Customer_selection As String, lc As Long
Dim User As String
Dim arr(0 To 2) As String
Set database = Worksheets("New Database")
Set data = Worksheets("Data")
arr(0) = VBA.DateTime.Date & " @ " & VBA.DateTime.Time
arr(1) = Application.UserName
arr(2) = txtNewComment.Value
If txtNewComment.Value = "" Then
MsgBox "No Comments Entered", vbExclamation
Exit Sub
End If
With data
lr = .Cells(Rows.Count, 1).End(xlUp).Row
Set rr = .range("A2:A" & lr).Find(database.range("B4"), lookat:=xlWhole)
lc = .Cells(rr.Row, 50).End(xlToLeft).Column + 1
If lc < 4 Then lc = 4
.range(.Cells(rr.Row, lc), .Cells(rr.Row, lc + 2)) = arr()
End With
Application.ScreenUpdating = True
Call UserForm_Initialize
txtNewComment = ""
End Sub
Private Sub UserForm_Initialize()
Customer_Comments.txtNewComment.SetFocus
Customer_Comments.label_accnumber.Caption = Sheet5.range("B4")
[B]'this is where I'm having issue.
txtComment = Application.WorksheetFunction.vlookup(label_accnumber, Sheet1.range("A2:DS27"), 22, False) & " - " & Application.WorksheetFunction.vlookup(label_accnumber, Sheet1.range("A2:DS27"), 23, False) & " - " & Application.WorksheetFunction.vlookup(label_accnumber, Sheet1.range("A2:DS27"), 24, False)[/B]
End Sub
I have identified that due to the vlookup, it only returns my specified values, but I'm really struggling to figure out a way to almost return the first 3 cells of choice, then offset these to return the next 3 cell values on the row below
and so forth.
Please help!