VBA - pop up window to return a list of data based on cells

JaguarSean

New Member
Joined
Jun 5, 2017
Messages
31
Hello all

New request this morning. I've been trying all sorts of things with formula and I think I'm going to need VBA to get this task done. I've got minimal experience using VBA so I need some help. Here's what I'm trying to achieve;

I would like for a pop up window to appear and list the contents of some cells which have a FALSE statement in another column.

Column B has a large list of labels (a huge mix of text essentially but I'll keep it simple with Label 123). Column B's text doesn't have any patterns. The text can be separated by some blank cells, and sometimes not, sometimes quite a few blank cells before the next cell with text. This is the data I want to appear in the pop up box but only if column E contains a FALSE in the corresponding row.

For example;

ABCDE
GROUP 1 - Enable
LABEL 1TRUE
LABEL 2FALSE
LABEL 3FALSE
LABEL 4TRUE
GROUP 2 - Condition
LABEL 5TRUE
LABEL 6FALSE

<tbody>
</tbody>

So in the above example, the pop up window would have a message that says something like " you have differences;" followed by a list of the FALSE conditions. To add to the complexity, the data sets are in groups. I'd like to quote the group number above the label differences in BOLD, the group description has been simplified for this example but is a complex naming structure that has no pattern such as group 1, group 2 etc.

There are ~450 labels in total over ~1400 rows, 7 groups in total, again all with no pattern to how they are arranged. Followed by a final statement along the lines of "do you agree with the differences?". The above condition would display something like this:

You have differences;

GROUP 1 - Enable
LABEL 2
LABEL 3

GROUP 2 - Condition
LABEL 6

Do you Agree with the differences?

For background. I'm comparing multiple data-sets with large amounts of data and I'd like a very simple window to aid the comparison and highlight differences in the data-set. There will almost always be differences but the aim to is try and reduce those over time so the FALSE statement will change to TRUE's meaning we have a more common approach.

Any questions or thoughts?

I can provide my document if required however I'd rather not make it public info.

Many Thanks for your help
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
You could do this with a pivot table.
Select your data, insert pivot table. Put the label in the row section and the section with the true or false in the filter. then ok.
Go to the pivot and select the filter and choose false, this will show all the items that are false with their labels.

Otherwise would a simple filter work?

The alternative in VBA would be to create forms and write code to capture the information. Creating the forms will take longer than the pivot tables but its up to you.
 
Upvote 0
Try this:-
Results in Msgbox.
Code:
[COLOR="Navy"]Sub[/COLOR] MG19Jun25
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Msg [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not IsEmpty(Dn.Offset(, -1).Value) [COLOR="Navy"]Then[/COLOR]
        Temp = Dn.Offset(, -1)
        [COLOR="Navy"]If[/COLOR] Not Msg = "" [COLOR="Navy"]Then[/COLOR] Msg = Msg & vbLf
        Msg = Msg & Temp & vbLf
    [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]If[/COLOR] Dn.Offset(, 3).Value = "False" [COLOR="Navy"]Then[/COLOR]
        Msg = Msg & Dn.Value & vbLf
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
MsgBox Msg
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
NB:- If you have a large amount of data, you could create a userform with a listbox.
The code below will load the required data into Listbox1 of the Userform.
Code:
[COLOR="Navy"]Sub[/COLOR] MG19Jun33
Option Explicit
Private [COLOR="Navy"]Sub[/COLOR] UserForm_Initialize()
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Msg [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not IsEmpty(Dn.Offset(, -1).Value) [COLOR="Navy"]Then[/COLOR]
        Temp = Dn.Offset(, -1)
        [COLOR="Navy"]If[/COLOR] Not Msg = "" [COLOR="Navy"]Then[/COLOR] Msg = Msg & vbLf
        Msg = Msg & Temp & vbLf
    [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]If[/COLOR] Dn.Offset(, 3).Value = "False" [COLOR="Navy"]Then[/COLOR]
        Msg = Msg & Dn.Value & vbLf
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
ListBox1.List = Split(Msg, vbLf)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Results in Msgbox.
Code:
[COLOR=Navy]Sub[/COLOR] MG19Jun25
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, Msg [COLOR=Navy]As[/COLOR] [COLOR=Navy]String,[/COLOR] Temp [COLOR=Navy]As[/COLOR] [COLOR=Navy]String[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    [COLOR=Navy]If[/COLOR] Not IsEmpty(Dn.Offset(, -1).Value) [COLOR=Navy]Then[/COLOR]
        Temp = Dn.Offset(, -1)
        [COLOR=Navy]If[/COLOR] Not Msg = "" [COLOR=Navy]Then[/COLOR] Msg = Msg & vbLf
        Msg = Msg & Temp & vbLf
    [COLOR=Navy]End[/COLOR] If
    [COLOR=Navy]If[/COLOR] Dn.Offset(, 3).Value = "False" [COLOR=Navy]Then[/COLOR]
        Msg = Msg & Dn.Value & vbLf
    [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]Next[/COLOR] Dn
MsgBox Msg
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick

Almost perfect...thank you.

Only problem is that there are quote a few 'FALSE' statement so my list is long and has pushed the 'OK/CLOSE' button off the bottom of the screen and I can't click it. What are my options?

Additionally, the list only seems to take into account the first three groups before it runs out of room so the next 4 are missing?
 
Last edited:
Upvote 0
The close Button is the "X" at the top right of the msgbox
I should try the Userform method with the Listbox.
The listbox will have a scroll bar for all your data.
 
Upvote 0
The close Button is the "X" at the top right of the msgbox
I should try the Userform method with the Listbox.
The listbox will have a scroll bar for all your data.

I can get to the X, thats no problem.

I think the listbox sounds like a good idea, unfortunately, something I've never heard of. If I insert your code I get errors. I assume I need to do other things in addition?
 
Last edited:
Upvote 0
Can you place a "forms button" or an active x "commandbutton" on your sheet with the code line:-
Code:
Userform1.show

If so I will only need to explain the userform bit.
Let me know !!!
 
Upvote 0
I can place a command button.

If I apply this Macro;

Sub Macro1()
'
' Macro1 Macro
'
Userform1.Show
'
End Sub


I get an error in the userform1.Show line
 
Upvote 0
The error is because you have not yet got a userform.
Follow details below:-
Any problems call back!!!

To Create Userform & ListBox. In Data sheet.
Click Alt + F11 to show VBEditor

If Properties window on left not showing, Click, Ctrl+R.

With code window showing
"To Insert Userform:-

From Vbtoolbar click "Insert", "Userform".
Userform appears in vbeditor window
Adjust Userform size by strectching corners/sides.

"To Insert Listbox":-
From VbToolBar select "View" "Toolbox", ToolBox appears.
From "ToolBox" , Click and drag "Listbox" (top right) to centre of Userform. Size as required.


"To Load Code" :-
Right Click Userform, Select "View Code", Code window appears.
Paste the second bit of code I sent into code window
Close Vbeditor

Test code by clicking your Button/CommandButton with that bit of code:- Userform1.show.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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