vBA On click

xtrato

New Member
Joined
Sep 14, 2016
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hi all Happy new Years to everyone.

So i have this situation , i was able to grab a VBA Code from another thread and combine it. But i need to expand on it, the basic principle is.

1735940238801.png


When someone clicks on the employee ID ( preferably the HOURS) a pop up with the "RAW INFORMATION" shows... so far i have this code, which i combined.


The following code belongs to the attached file.

VBA Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
 
    Dim stAddress As String, x As Long, lRow As Long
    If Not Intersect(Target, Range("B2:B10")) Is Nothing Then
        lRow = Sheet2.Range("B:B").Find(what:=Target).Row
        For x = 0 To 6
            stAddress = stAddress & Sheet2.Range("Data").Cells(lRow, x + 1) & Chr(13)
        Next x
       
                With UserForm1
    ' Increase the height by 20 points
    .Height = .Height + 70
   .Width = .Width + 120
End With
       
        With UserForm1
            .Show
            .Left = 180
            .Caption = "Clocks " & Target.Value
            .TextBox1 = stAddress
            .Top = ActiveCell.Top + ActiveCell.Height + .Height
            .TextBox1.Height = .TextBox1.Height + 70 ' Increase height by 100 points
            .TextBox1.Width = .TextBox1.Width + 100 ' Increase width by 100 points

        End With
       

        stAddress = ""
        lRow = 3
    End If
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("C2:C100")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("B2") = Target.Value
End If
End Sub


Addresses.xlsm
ABCDE
1Name
2DollyDolly
3Joe
4Roxy
5
6Joe
7
8Dolly
9Joe
10
11Dolly
12
13
14
Sheet1
Cells with Data Validation
CellAllowCriteria
B2:B9List=OFFSET(Data,1,0,ROWS(Data),1)
C2:C3List=OFFSET(Data,1,0,ROWS(Data),1)
C11List=OFFSET(Data,1,0,ROWS(Data),1)



DATA SHEET:

Addresses.xlsm
ABCDEFGH
1NameAddress 1Address 2Post CodePost CodeAddress 1
2Joe6 Some streetLeedsLS2 1ABxx6 Some street
3Dolly8 Somewhere else streetA TownLS2 1ABxxTEST
4Roxy10 Another RoadAnother TownLS2 1ABxTEST
5Fred6 Some streetTown FredLS2 1ABxxxTEST
6Dolly8 Somewhere else streetA TownLS2 1ABxxTEST
7
Data



So when i do infact click on DOLLY: i get the followin pop up successfully.

1735941191531.png



and thats great; now , back to my original problem... So the pop up is great, works as intended, now i want to apply that to my sheet , again with the following result:

when someone click son the ID COLUMN A : the pop up shows. ( now based on the vBA above - it needs to modify a cell , so that cell can be hidden) ,

1735940238801.png

now the popup i want it to display the data that is shown below on a different RAW DATA SHEET:
.
Cell Formulas
RangeFormula
BB2:BB16BB2=XLOOKUP(D2,PayrolHRS!$B$1:$B$1111,PayrolHRS!$C$1:$C$1111,0)
BC2:BC16BC2=IF(AND(V2=0,AC2<5),0.5,0)
BD2:BD16BD2=CONCATENATE(,TEXT(G2,"DDD-DD"),"|",REPLACE(A1, 1, 4, ""),"|",H2," ")
BA7:BA16BA7=CONCATENATE(PROPER(E7)," ",PROPER(F7))


Now - this data is orgnized in columns - not in rows as the orignal code ; so i want to instead, display all the in BD That pertains to the Employee in BA - on this example - there would be 5 LINES that should show on the popup

so below is a screenshot of what "ULTIMATELLY" i would like when they click a name :

1735941722003.png

Any help would be Greatly APPRECIATED!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You'll need to post your workbook to a download site then post the link here.
 
Upvote 0
ok , here are both files :


ive removed excess data

So from the PRL File , id want all data matched in column A for user ID - to column N all times , as shown in the picture above, Using the VBA from the addresses file,
 
Upvote 0
Hoping I correctly understood your stated goal. Here is a macro that displays the data in a LABEL located on UserForm1.

VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim TargetRow As Long
    Dim CellValue As String ' Ensure that CellValue is treated as a String
    Dim ws As Worksheet
    Dim MultiLineText As String
    Dim Items() As String
    Dim Item As Variant
    Dim i As Integer
    
    ' Set the correct worksheet reference
    Set ws = ThisWorkbook.Sheets("Main")
    
    ' Check if the selected cell is in column A (adjust as needed)
    If Not Intersect(Target, Me.Columns("A")) Is Nothing Then
        ' Ensure only a single cell is selected
        If Target.Cells.Count = 1 Then
            ' Get the row number of the selected cell
            TargetRow = Target.Row
            
            ' Get the value from column H (ensuring it's treated as text)
            CellValue = CStr(ws.Cells(TargetRow, "H").Value)
            
            ' Trim the value to remove extra spaces
            CellValue = Trim(CellValue)
            
            ' Initialize an empty string to store the multi-line text
            MultiLineText = ""
            
            ' Check if there is any value in column H
            If Len(CellValue) > 0 Then
                ' Split the data by spaces into an array
                Items = Split(CellValue, " ")
                
                ' Loop through each item in the array and create a formatted line
                For i = LBound(Items) To UBound(Items)
                    ' Add each item followed by a line break
                    MultiLineText = MultiLineText & Items(i) & vbCrLf
                Next i
                
              
                ' Initialize and show the UserForm
                With UserForm1
                    ' Ensure WordWrap is enabled to support multiple lines
                    .Label1.WordWrap = True ' Enable WordWrap for the label to display multi-line text
                    
                    ' Set the Label1 AutoSize to False to control size manually
                    .Label1.AutoSize = False
                    .Label1.Width = 200 ' Set the label width to a fixed value (adjust as needed)
                    .Label1.Caption = MultiLineText ' Set the label text to the formatted multi-line content
                    
                    ' Set the label size based on the content length
                    .Label1.Height = (Len(MultiLineText) / 10) * 15 ' Adjust this multiplier as needed to ensure enough space
                    
                    
                    .Show ' Show the UserForm
                End With
            Else
                MsgBox "No data found in column H of Main for the selected row.", vbInformation
            End If
        End If
    End If
End Sub

The UserForm properties were set as: ShowModal = False

The Label1 properties were set as: WordWrap = True ..... AutoSize = False

Review the macro and edit the column designations to match your needs there.
This macro was placed in the MAIN worksheet module located in the workbook PRL.xlsb

You can download the revised workbook here : Internxt Drive – Private & Secure Cloud Storage
 
Upvote 0
alright thanks , i think we are on to something, So in Column H - has its own Formula that (Xlookup) that looks up the Total hours of the employee so that one we dont need it to be modifed .

what i want is when you click on EMP ID (COL A from "main" Sheet) is to show the RAW Data from "Data" sheet in column "N" .. so for exp jose would have 5 lines of data displayed

as such:
1736050601998.png


so to explain more-less ; like doing an xlookup and show all results in the Userform Popup of that selected cell:

Excel Formula:
=XLOOKUP(A5,data!A:A,data!N:N)
 
Upvote 0
so , of course, we learn as we go .. its like doing a filter then:

Excel Formula:
=FILTER(data!N1:N12,data!B1:B12=main!A5,"")

but place this result inside that text pop up box when clicked on the cell A5
 
Upvote 0

Forum statistics

Threads
1,225,287
Messages
6,184,076
Members
453,210
Latest member
GravyG_123

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