Userform: Looking for something similar to a Vlookup

ineedhelp1

New Member
Joined
Apr 22, 2015
Messages
15
Hi

I have a data sheet layed out as follows:

Customer ADateApp UserComment1DateApp UserComment2
Customer BDateApp UserComment1DateApp UserComment2
Customer CDateApp UserComment1DateApp UserComment2

<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!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,835
Messages
6,121,880
Members
449,057
Latest member
Moo4247

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