VBA code to perform action from MsgBox

Status
Not open for further replies.

CJG19

New Member
Joined
Jul 12, 2021
Messages
40
Office Version
  1. 2010
Platform
  1. Windows
Hi All,

I am trying to get a yes/no pop up box, which works, but if you select yes, change the active cell to Yes and turn green, if no, it should stay no but colour the active cell red, can anyone help please?

1643027974447.png


VBA Code:
Sub Final_Account_Cert()

Range("BO5").Select
'Begin the loop
Do Until ActiveCell.Value = ""
If ActiveCell.Value = "NO" And ActiveCell.Offset(0, -2) > 0 And ActiveCell.Offset(0, -1) = 0 Then
'Display a message to the user
MsgBox "Have We Received Final Account Certificate?", vbYesNo, "Thank you"
'Turn cell green and change text to Yes
If AnswerYes = vbYes Then
ActiveCell.Value = "YES"
ActiveCell.Interior.Color = 65280
End If
'Format Invoice Code Cell to Red
ActiveCell.Interior.Color = 255
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub

TIA

CJG19
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about
VBA Code:
Sub Final_Account_Cert()

Range("BO5").Select
'Begin the loop
Do Until ActiveCell.Value = ""
If ActiveCell.Value = "NO" And ActiveCell.Offset(0, -2) > 0 And ActiveCell.Offset(0, -1) = 0 Then
   'Display a message to the user
   If MsgBox("Have We Received Final Account Certificate?", vbYesNo, "Thank you") = vbYes Then
   'Turn cell green and change text to Yes
      ActiveCell.Value = "YES"
      ActiveCell.Interior.Color = 65280
   Else
      'Format Invoice Code Cell to Red
      ActiveCell.Interior.Color = 255
   End If
End If
   ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
Duplicate to: Trouble with a loop

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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