Display Specific data in selected range within UserForm ListBox

PGMouton

New Member
Joined
Aug 12, 2020
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good Day i am having some trouble with my excel spreadsheet.
I am using VBA to get info from one of our Sites Via SQL Query i have the data and all is working as should.

This Spreadsheet is not fixed when a GRV is closed then this get new data from the server VIA SQL QUERY so i need this to be Dinamic

When i press the Button (Display Open GRV's) i want to show the selected Branch(BSCDC) on my UserForm
at this moment i am displaying all the info in my UserForm.

But when i select (BSCEV) the display Button must only show (BSCEV).

VBA Code:
Option Explicit
Sub RectangleRoundedCorners1_Click()


'populate a multi-column ListBox from a worskheet range, using AddItem method and List property
        Dim counter As Long
        Dim totalRows As Long
        Dim r As Long
        
        'determine total number of rows in column A
        totalRows = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
        counter = 0
        
        'ListBox gets populated with all rows in column A:
        Do
        
        With UserForm1.ListBox1
            counter = counter + 1
            'create a new row with Additem
            .AddItem Sheet1.Cells(counter, 1).Offset(1, 1).Value
            'add item in 2 column of a row
            .List(.ListCount - 1, 1) = Sheet1.Cells(counter, 1).Offset(1, 1).Value
            'add item in 3 column of a row
            .List(.ListCount - 1, 2) = Sheet1.Cells(counter, 1).Offset(1, 2).Value
            'add item in 4 column of a row
            .List(.ListCount - 1, 3) = Sheet1.Cells(counter, 1).Offset(1, 3).Value
            'add item in 5 column of a row
            .List(.ListCount - 1, 4) = Sheet1.Cells(counter, 1).Offset(1, 4).Value
            'add item in 6 column of a row
            .List(.ListCount - 1, 5) = Sheet1.Cells(counter, 1).Offset(1, 5).Value
            'add item in 7 column of a row
            .List(.ListCount - 1, 6) = Sheet1.Cells(counter, 1).Offset(1, 6).Value
        End With
        
            Loop Until counter = totalRows

UserForm1.TextBox1.Value = WorksheetFunction.Sum(Range(Range("F2"), Range("F100"))) 'Display The Total EXCL
UserForm1.TextBox2.Value = WorksheetFunction.Sum(Range(Range("G2"), Range("G100"))) 'Display The Total VAT
UserForm1.TextBox3.Value = WorksheetFunction.Sum(Range(Range("E2"), Range("E100"))) 'Display The Total Count

    UserForm1.Show

End Sub


Hope i gave all the info if not please let me know i am glad to help with any other Questions.
 

Attachments

  • Capture.PNG
    Capture.PNG
    43.1 KB · Views: 99
  • Capture1.PNG
    Capture1.PNG
    45 KB · Views: 100

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Do you mean you only ever want to view the data that has 'BSCEV' in the first column?

The most straightforward way to do that would be with an If statement.
VBA Code:
With UserForm1.ListBox1
    If Sheet1.Cells(counter, 1).Offset(1, 1).Value = "BSCEV" Then
        counter = counter + 1
        'create a new row with Additem
        .AddItem Sheet1.Cells(counter, 1).Offset(1, 1).Value
        'add item in 2 column of a row
        .List(.ListCount - 1, 1) = Sheet1.Cells(counter, 1).Offset(1, 1).Value
        'add item in 3 column of a row
        .List(.ListCount - 1, 2) = Sheet1.Cells(counter, 1).Offset(1, 2).Value
        'add item in 4 column of a row
        .List(.ListCount - 1, 3) = Sheet1.Cells(counter, 1).Offset(1, 3).Value
        'add item in 5 column of a row
        .List(.ListCount - 1, 4) = Sheet1.Cells(counter, 1).Offset(1, 4).Value
        'add item in 6 column of a row
        .List(.ListCount - 1, 5) = Sheet1.Cells(counter, 1).Offset(1, 5).Value
        'add item in 7 column of a row
        .List(.ListCount - 1, 6) = Sheet1.Cells(counter, 1).Offset(1, 6).Value
    End If
End With
 
Upvote 0
Sorry for the late reply It work 100% thanks so much.
i did end up changing it a lot after.
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,933
Members
449,195
Latest member
Stevenciu

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