Macro to show Message box in cells as well

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have a macro to display a message box

I need to show each message in a seperate cell , but all the message displays on one cell


it would to show each message on a separate cell on sheet 'Macro"


It would be appreciated if someone could amend my code


Code:
 Sub Variance_Message()

Dim ws As Worksheet, r As Range, msg As String, ff As String
For Each ws In Sheets
    Set r = ws.Columns("b").Find("Variance")
    
    If Not r Is Nothing Then
        ff = r.Address
        Do
           If 5 < Abs(Val(CStr(r.Offset(0, 1).Value))) Then
               msg = msg & ws.Name & r.Address(0, 0)
            End If
            Set r = ws.Columns("b").FindNext(r)
        Loop Until ff = r.Address
    End If
   
Next
If Len(msg) = 0 Then
   MsgBox "No Variances Found"
   Exit Sub
Else
   MsgBox msg
   Worksheets("Macro").Range("a1:A15").Value = msg
End If


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Maybe
Code:
Sub Variance_Message()

Dim ws As Worksheet, r As Range, msg As String, ff As String, Sp As Variant
For Each ws In Sheets
    Set r = ws.Columns("b").Find("Variance")
    
    If Not r Is Nothing Then
        ff = r.Address
        Do
           If 5 < Abs(Val(CStr(r.Offset(0, 1).Value))) Then
               msg = msg & ws.Name & r.Address(0, 0) & ","
            End If
            Set r = ws.Columns("b").FindNext(r)
        Loop Until ff = r.Address
    End If
   
Next
If Len(msg) = 0 Then
   MsgBox "No Variances Found"
   Exit Sub
Else
   MsgBox msg
   Sp = Split(msg, ",")
   Worksheets("Macro").Range("a1").Resize(UBound(Sp) + 1).Value = Sp
End If


End Sub
 
Upvote 0
In what way isn't it working?
 
Upvote 0
Hi Fluff


These are appearing in the col a as follows below


Book1
A
1BR1B128
2BR1B128
3BR1B128
4
Sheet1



Each item between the commas in the message box must be show in its own cell in Col A from row1 onwards

Br1 B128
Br2 B195 etc
 
Upvote 0
Got ya, try
Code:
Worksheets("Macro").Range("a1").Resize(UBound(Sp) + 1).Value = Application.Transpose(Sp)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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