Hi there
I've set up a database in Excel where comments can be added to customers accounts via the user form.
Basically, the comment is typed into the text box and it performs a vlookup (so it knows where to past the data/comments).
On the userform I have a button with a label of "Load Comments" which performs a Vlookup and selects the correct comments to load.
Code is as follows:
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
database.range("S48:AA48").ClearContents
Application.ScreenUpdating = True
End Sub
Private Sub Load_Comments_Button_Click()
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)
End Sub
Everytime a new comment is added, it pastes the application user, date and new comment into the last block of cells in my DATA sheet.
What I need is for the VLOOKUP to show all comments (not just columns 22, 23 and 24 - This could be an infinite ammount of comments so I don't really want to add hundred (or throusands of Vlookups) into the View Comments button code. So I think I almost have to offset to check if comments exist then show this on a seperate vbnewline for each block of 3 (application user, date and comment)
Any suggestions on how to do this elegantly?
Also, rather than viewing the comments by clicking the button, I'm also having an issue auto loading the comments upon userform.show under the following code:
Sub load_comments()
Customer_Comments.label_accnumber.Caption = Sheet5.range("B4")
Customer_Comments.Show
End Sub
(The above is the macro for a button on my spreadsheet but I get a debug error on the Vlookup when I paste this into the above).
Bookmarks