stop string or range before it goes forward to next command

STEEL010

Board Regular
Joined
Dec 29, 2017
Messages
76
Hi There,

I have an VBA macro an it must stop when cell is not filled in , I want it to go back to the sheet to fill in the cell and the it must proceed whit the next command.

Steel010
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I'm guessing that this is in some loop. The structure that I would use is.

Code:
For Each oneCell in someRange

    ' some code
 
    If oneCell = vbNullString Then
        oneCell.Value = Application.InputBox("Enter Something", type:=2)
    End If

    ' more code

Next oneCell
 
Last edited:
Upvote 0
Hi Mike,

hereby my code, what must go in between?


Private Sub CommandButton1_Click()

End Sub
Sub Checkofcells(Cancel As Boolean)
'check cells before sending
For Each cell In Range("B5,B11,H6,H8,H9,C16,D42")
If cell.Value = "" Then
MsgBox "Please complete red field before sending.", vbCritical, "Missing Info"
cell.Select
Cancel = True
Exit Sub
End If
Next

End Sub
Sub SendWorkBook()
'Update 20171227
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim FilePath As String
Dim FileName As String
Dim rng As Range
Dim cel As Range
Dim OutLookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Application.ScreenUpdating = False
Set Wb = Application.ActiveWorkbook
ActiveBook.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & ""
FileName = Wb.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Set OutLookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutLookApp.CreateItem(0)
Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
With OutlookMail
.To = "Btest@atest.com"
.CC = ""
.BCC = ""
.Subject = "from"
.Body = ""
.Attachments.Add Wb2.FullName
.Send
'Display
End With
Wb2.Close
Kill FilePath & FileName & xFile
Set OutlookMail = Nothing
Set OutLookApp = Nothing
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Like this???

Sub Checkofcells(Cancel As Boolean)
'check cells before sending
For Each cell In Range("B5,B11,H6,H8,H9,C16,D42")
If oneCell = vbNullString Then
oneCell.Value = Application.InputBox("Enter Something", type:=2)
cell.Select
Cancel = True
Exit Sub
End If
Next

End Sub
 
Upvote 0
Yes. You still have to change the variable names from my oneCell to your code's cell, but that's where the code goes.
 
Upvote 0
Mike,

still do not see, I'm not the most wiz kid in vba. so please give an example
most appreciated
 
Upvote 0
this is

Sub Checkofcells()
'check cells before sending
For Each cell In Range("B5")
If cell("B5").Value = vbNullString Then
cell("B5").Value = Application.InputBox("Please complete red field before sending.", Type:=2)
cell.Select
Exit Sub
End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,734
Messages
6,132,417
Members
449,727
Latest member
Aby2024

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