Add a stipulation to my display SUB

I have a display function that will display data from my worksheet to a locked textbox, Now i want to build upon my code to only display if the cells in column
D = Environ("Username")

Open in new window


The code i am currently using for displaying the code is
Private Sub CommandButton39_Click()

    Range("B1:B37").Select
    ActiveWorkbook.Worksheets("FUN1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FUN1").Sort.SortFields.Add Key:=Range("B1"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("FUN1").Sort
        .SetRange Range("A1:D37")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Me.TextBox4.Value = ""
Dim wb As Workbook
Workbooks("Working.xlsm").Activate
Dim arrIn As Variant
Dim arrOut()
Dim i As Long
Dim j As Long

    arrIn = Sheets("FUN1").Range("A1").CurrentRegion
    
    ReDim arrOut(1 To UBound(arrIn))
    
    For i = 1 To UBound(arrIn)
    
        For j = 1 To UBound(arrIn, 2) - 1
            arrOut(i) = arrOut(i) & arrIn(i, j) & vbTab
        Next j
        
        arrOut(i) = arrOut(i) & arrIn(i, j)
    
    Next i
    
    With TextBox4
        .MultiLine = True
        .Value = Join(arrOut, vbCrLf)
    End With
End Sub

Open in new window

david franciscoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
Can you attach the workbook
0
Rory ArchibaldCommented:
Untested, but try this:

Private Sub CommandButton39_Click()

    Range("B1:B37").Select
    ActiveWorkbook.Worksheets("FUN1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FUN1").Sort.SortFields.Add Key:=Range("B1"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("FUN1").Sort
        .SetRange Range("A1:D37")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Me.TextBox4.Value = ""
Dim wb As Workbook
Workbooks("Working.xlsm").Activate
Dim arrIn As Variant
Dim arrOut()
Dim i As Long
Dim j As Long
Dim counter As Long
Dim outRow As Long
Dim sUser As String
sUser = VBA.LCase$(Environ("username"))
With Sheets("FUN1").Range("A1").CurrentRegion
    arrIn = .Value
    counter = Application.CountIf(.Columns(4), sUser)
    
    ReDim arrOut(1 To counter)
    outRow = 1
    For i = 1 To UBound(arrIn)
        If VBA.LCase$(arrIn(i, 4)) = sUser Then
            For j = 1 To UBound(arrIn, 2) - 1
                arrOut(outRow) = arrOut(outRow) & arrIn(i, j) & vbTab
            Next j
            
            arrOut(outRow) = arrOut(outRow) & arrIn(i, j)
            outRow = outRow + 1
        End If
    Next i
    
    With TextBox4
        .MultiLine = True
        .Value = Join(arrOut, vbCrLf)
    End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
david franciscoAuthor Commented:
@Roy Cox, no i cannot.

@Rory Archibald, it worked great! thanks for the help! i had tried a couple of solutions that actually were close to what you posted, and i had to add another end with before the end sub of your code, but it worked perfectly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.