Blank Display in MsgBox

diamantebonita

New Member
Joined
May 25, 2011
Messages
22
I basically copied this code out of the Excel 2010 Power Programming Guide, pg. 408, and changed it slightly to fit my needs.

list = ""
For r = 1 To 10
For c = 27 To 29
list = list & Cells(r, c).Text
If c <> 29 Then list = list & vbTab
Next c
list = list & vbCrLf
Next r
MsgBox list

The previous section of my code copies text to a separate area of the worksheet, and this section of code is supposed to display it as a list on a MsgBox that displays when the workbook is opened.

However every so often the list fails to display. The msgbox will pop up but it will simply be blank. I think it has something to do with the

'If c <> 29 Then list = list & vbTab' line

But I cant figure it out.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Here's a simpler version of your code, and I think this does what you want:
Code:
Sub test()
Dim c As Range, list As String
For Each c In Range("AA1:AC10")
    list = list & c & IIf(c.Column = 29, vbLf, vbTab)
Next
MsgBox list
End Sub
 
Upvote 0
BTW, it is better to describe what it is you are trying to do rather than reference a book that we might not have.
 
Upvote 0
The code you gave was MUCH simpler, thanks! But the list still doesnt display consistently in the msgbox. So I will have to search through the rest of the code to see what the problem is.

thanks for your reply.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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