Consulting

Results 1 to 3 of 3

Thread: Stop macro running if row empty

  1. #1
    VBAX Regular
    Joined
    Dec 2020
    Posts
    6
    Location

    Arrow Stop macro running if row empty

    Hi,

    This is my first ever post on any forum ever so firstly I apologise if I don't follow the correct protocol! I have little knowledge of VBA but learning via experience (and youtube) rather than a course

    I've got a Macro that copies a row and paste's the data to another workbook where it's stored, is it possible to prevent the macro from being run if any of the cells in row 3 are empty? (Row 3 - B3 to K3)

    This is my macro to "Submit" the data:

    Sub submit()
    '
    ' submit Macro
    '

    '
    Rows("3:3").Select
    Selection.Copy
    Workbooks.Open Filename:="N:\REPORTING\Liam\MTA Log.xlsm"
    Rows("3:3").Select
    Selection.Insert Shift:=xlDown
    Range("B3").Select
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("B3").Select
    End Sub


    Thank you in advance,
    PS

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    maybe:
    Sub submit2()
    If Application.CountBlank(Range("B3:K3")) = 0 Then
      With Rows(3)
        .Copy
        Workbooks.Open Filename:="N:\REPORTING\Liam\MTA Log.xlsm"
        Rows(3).Insert
        ActiveWorkbook.Close True
        Application.CutCopyMode = False
        .ClearContents
      End With
      Range("B3").Select
    Else
      MsgBox "blanks in B3:K3"
    End If
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Dec 2020
    Posts
    6
    Location
    Hi P45cal,

    Thank you so much! That works perfectly, appreciate your help

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •