In this article, we will create a double click workbook event to create a message box for the record.
Raw data for this example consists of IT department data, which includes Name, Age, Department, Language known and Country.
When we double click on a cell, all the details of that particular row will be displayed in a message box.
Logic explanation
In this article, we have used Worksheet_BeforeDoubleClick event to create a message box. This event will be fired when we double click on a particular cell.
Code explanation
If Target.Column > 5 Then Exit Sub
Above code is used to restrict double click event to work only for first 5 columns.
For intCounter = 1 To 5
txt = txt & Cells(Target.Row, intCounter) & vbLf
Next intCounter
Above code is used to concatinate the data in a row.
vbLf is used to insert line feed.
Please follow below for the code
'Add code in Sheet module Option Explicit Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 'Declaring variables Dim intCounter As Integer Dim txt As String 'Checking that target column should not be greater than 5 If Target.Column > 5 Then Exit Sub Cancel = True 'Getting values of target row in string For intCounter = 1 To 5 txt = txt & Cells(Target.Row, intCounter) & vbLf Next intCounter 'Displaying string message MsgBox txt End Sub
If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.