Consulting

Results 1 to 3 of 3

Thread: VBA Excel clear cells causes error 400

  1. #1
    VBAX Regular
    Joined
    Jul 2016
    Posts
    6
    Location

    Question VBA Excel clear cells causes error 400

    Private Sub Workbook_Open()
    Application.WindowState = xlMaximized
    End Sub
    
    Sub NextInvoice()
    Sheets("InvoiceB").Range("F5").Value = Sheets("InvoiceB").Range("F5").Value + 1
    Sheets("InvoiceB").Range("C8:C14").ClearContents
    Sheets("InvoiceB").Range("F8:F14").ClearContents
    Sheets("InvoiceB").Range("A17:G24").ClearContents
    Sheets("InvoiceB").Range("A29:F36").ClearContents
    End Sub
    
    Sub SaveInvWithNewName()
    Dim NewFN As Variant
    ActiveSheet.Copy
    NewFN = "C:\invoices\Inv" & Range("F5").Value & ".xls"
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlWorkbookNormal
    ActiveWorkbook.Close
    NextInvoice
    End Sub
    For some reason i get an error 400 i am sure it has to do with 2nd ClearContents on the invoice cells are not protected i checked.
    Seems to error 400 on merged text cells not sure how to get around it?.
    Last edited by Galdorf; 07-08-2016 at 10:26 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    F8:F14?
    2nd ClearContents on the invoice
    Try clearing F8 alone

    VBA doesn't play at all well with merged cells. Usually you can Format a group of cells with Horizontal Alignment = "Center Across Selection." VBA likes that.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Jul 2016
    Posts
    6
    Location
    Quote Originally Posted by SamT View Post
    F8:F14?
    Try clearing F8 alone

    VBA doesn't play at all well with merged cells. Usually you can Format a group of cells with Horizontal Alignment = "Center Across Selection." VBA likes that.
    I kind of found an easier way name the merged cells then :

    Range("jobamt1").MergeArea.ClearContents

Posting Permissions

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