How to record values in a For loop to be displayed by a message box after the loop is done

bellg

New Member
Joined
May 13, 2014
Messages
29
Hi, I'm not sure how to progressively add values that meet a certain condition into a message box, but I think it's possible.

Code:
a = integer
a = 1

        For a = 1 To 21
            If ActiveCell.Offset(a, 15).Value = ActiveCell.Offset(1, 11).Value Then
                MsgBox ("This  " & ActiveCell.Offset(a, 11).Value & " wasn't added to the list.)
            End If
        Next a

MsgBox (All values not added)

I'd like to see a result that shows something like:

Msgbox ("These weren't added:" & vbCrLf &
ActiveCell.Offset(a, 15).Value & vbCrLf &' when a = 3
ActiveCell.Offset(a, 15).Value & vbCrLf &' when a = 10
ActiveCell.Offset(a, 15).Value & vbCrLf &' when a = 11
ActiveCell.Offset(a, 15).Value)' when a = 21

for all values of "a" when it meets my condition.

Thanks in advance for any help.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hello,

can you pls try to tell me, what exactly you want to do? :) I have some strange feeling, that there is some better way how to achieve your target :)
 
Upvote 0
Just use a string variable like this - tweak it to get all the things you want in it.
Rich (BB code):
Dim msg As String
A = 1

        For A = 1 To 21
            If ActiveCell.Offset(A, 15).Value = ActiveCell.Offset(1, 11).Value Then
                msg = msg & vbNewLine & "This  " & ActiveCell.Offset(A, 11).Value & " wasn't added to the list."
            End If
        Next A

MsgBox msg
 
Upvote 0
this code works, The issue is, that I am not sure, if you are offseting correct cells and values, what exactly is not working? And if you are using activecell to macro, you have to use probably worksheet_change function....if you have it on button after every manual input, its soo complicated
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,349
Members
449,155
Latest member
ravioli44

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