+ Reply to Thread
Results 1 to 3 of 3

Macro randomly misses out on a cell.

  1. #1
    Registered User
    Join Date
    10-19-2010
    Location
    .
    MS-Off Ver
    .
    Posts
    10

    Macro randomly misses out on a cell.

    Hey guys.

    I'm fairly new to VBA. I recently created a macro that extracts data and puts it into a new spreadsheet. Now it works fairly well, and today I tried it on a sheet with thousands of rows of data. There are two adjacent columns in the spreadsheet for which there are numbers in each column. A debit and credit column. If you aren't familiar, basically all the numbers that appear in the debit column should be in the credit column as well and in the end the sums of each column should match up. Now my macro takes all the numbers from each column and puts them all in a single column and assigns it as a positive number if its from debit and negative if its from credit. It's obvious that the sum of that column should be 0 at as well since all the postivie and negative numbers should cancel out. However for some reason my macro missed out on a single cell from the credit column which gave me a discrepancy. The same number from the debit column was copied but not from the credit column. Now there will never be two adjacent cells filled with numbers, they will always either both be blank or only one of the debit or the credit column will have a number. This is the portion of the code that handles what to do.

    Please Login or Register  to view this content.
    I'm confused why it just missed out on a single cell of data. The columns basically looked like this but with hundreds of rows of data:

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Macro randomly misses out on a cell.

    Workbook Event code should be added to the workbook code module:

    Copy the Excel VBA code that you want to use
    Select the workbook in which you want to store the code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    In the Project Explorer, find your workbook, and open the list of Microsoft Excel Objects
    Right-click on the ThisWorkbook object, and choose View Code
    Where the cursor is flashing, choose Edit | PasteTo best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.


    On this page, below the message box, you will find a button labelled 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.


    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.


    To upload a file from your computer, click the 'Browse' button and locate the file.


    To upload a file from another URL, enter the full URL for the file in the second box on this page.
    Once you have completed one of the boxes, click 'Upload'.


    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-19-2010
    Location
    .
    MS-Off Ver
    .
    Posts
    10

    Re: Macro randomly misses out on a cell.

    Hello.

    Ok I made a sample file as you asked and will upload it.
    The run button on the top will run the macro in question. It will spit out a new worksheet starting with "BID" followed by 4 random numbers. In that worksheet you want to look at column "H" and it should sum to 0. However in this case it doesn't. It seems like the macro works fine but it misses out on a cell in the original worksheet. The cell in question is "I1174". In the BID sheet, the debit column values should be positive and credit should be negative and should all be in the same column. It missed out on that cell when copying the credit column values, but copied everything else before and after it.
    Last edited by Glenn Kennedy; 10-24-2019 at 08:16 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1