get error VBA 400

Abdullah S. Alshehri 0 Reputation points
2023-08-21T11:28:02.8033333+00:00

I have an repeort to run with more than one sheet when I run it give error 400 as need the from VBA to collect all data in sheet in one sheet

please support to fix this issues

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,919 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,936 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AllenXu-MSFT 20,666 Reputation points Microsoft Vendor
    2023-08-22T05:50:11.55+00:00

    Hi @Abdullah S. Alshehri,

    The error code 400 in VBA typically means that there is an issue with the syntax of the code. It is difficult to provide a specific solution without seeing the code that is causing the error. However, based on the information provided, it sounds like you may need to consolidate data from multiple sheets into one sheet before running the report. You can do this using VBA code by copying the data from each sheet and pasting it into the consolidated sheet. Here is some sample code that you can modify to fit your specific needs:

    Sub ConsolidateData()
        Dim ws As Worksheet
        Dim lastRow As Long
        Dim destRow As Long
        
        'Set the destination sheet
        Set destSheet = ThisWorkbook.Sheets("ConsolidatedData")
        
        'Loop through each sheet in the workbook
        For Each ws In ThisWorkbook.Worksheets
            'Skip the destination sheet
            If ws.Name <> destSheet.Name Then
                'Find the last row in the source sheet
                lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
                
                'Copy the data to the destination sheet
                ws.Range("A1:Z" & lastRow).Copy destSheet.Range("A" & destRow)
                
                'Update the destination row counter
                destRow = destSheet.Cells(destSheet.Rows.Count, "A").End(xlUp).Row + 1
            End If
        Next ws
    End Sub
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Tanay Prasad 2,125 Reputation points
    2023-08-22T05:59:09.2833333+00:00

    Hi,

    Here are some steps you can try-

    1. Ensure that your workbook is not protected or doesn't restrict the code to run in any way.
    2. Make sure that your VBA code is compatible with your current version of Excel.
    3. Make sure your device has enough memory available to run your task.
    4. Debug your code and find out what's wrong, identify potential errors, and fix them.

    If these methods do not work for you, here is an article for your help.

    Best Regards


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.