+ Reply to Thread
Results 1 to 12 of 12

[VBA] SUMIF coding problem with a file

  1. #1
    Registered User
    Join Date
    07-23-2014
    Location
    Napoli
    MS-Off Ver
    Office 2010
    Posts
    6

    Exclamation [VBA] SUMIF coding problem with a file

    Dear all,

    i am a beginner programmer about VBA mainly for Excel Applications.

    Please i need your help about a problem that feels me sick.

    I try to create the following macro:

    1. Open an excel file (and it's ok)

    Please Login or Register  to view this content.
    2. Load a sheet (and it's ok)

    Please Login or Register  to view this content.
    3. apply the sumif (it doesn't work with the file loades at point 1 but it works fine with the main sheet)

    NOTE: the variables lv_stringa_appogio is a String and lv_counter_hours is Double
    Please Login or Register  to view this content.
    The error occurs when i call sumif is Error 13 (i have tried to use only WorksheetFunction.Sumif... but the result is an other error).

    i hope in a your help and reply.

    Best regards.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: [VBA] SUMIF coding problem with a file

    It would probably help if you posted a sample workbook with some typical data demonstrating the problem.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-23-2014
    Location
    Napoli
    MS-Off Ver
    Office 2010
    Posts
    6

    Re: [VBA] SUMIF coding problem with a file

    hello TMS, thanks a lot, in the following table an example:

    Code Value
    XA 10
    2 4
    3 5
    4 7
    XA 10
    6 7
    7 9
    XA 10
    9 6


    i want sum the vaules with the label "XA" that are on an other file.

    Regards.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: [VBA] SUMIF coding problem with a file

    That's not a sample workbook ...

  5. #5
    Registered User
    Join Date
    07-23-2014
    Location
    Napoli
    MS-Off Ver
    Office 2010
    Posts
    6

    Re: [VBA] SUMIF coding problem with a file

    Why?

    i have only two columns. Could you explain it in a better way?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: [VBA] SUMIF coding problem with a file

    Why? Because I have no plans to set up an empty workbook, copy your data into it, try and format it like the real thing, and then copy and paste your code into it so I can test and diagnose your problem. And, if it works for me, all that has been proved is that it is something to do with your data. That's why.

    Your problem, and you're on your own with it if you can't be bothered helping others to help you.

    Don't expect any further input from me.

  7. #7
    Registered User
    Join Date
    07-23-2014
    Location
    Napoli
    MS-Off Ver
    Office 2010
    Posts
    6

    Re: [VBA] SUMIF coding problem with a file

    Hello TMS, why are u angry with me? or it seems so. I can't solve my problem. Excuse me for my reply but i am so sick about this code.

    I understand two things:


    1. the code works for the sheet where the code is
    2. the problem is about the file.

    I hope about a your help and i thank you about your post.

    Do you know if the sumif function has a problem using the files ?

    Regards.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: [VBA] SUMIF coding problem with a file

    OK, that's not anger you are "hearing", it is frustration. You're wasting my time because you won't help me to help you. And it's wasting your time because you're not getting the solution that you need.

    You have provided some "samples" of the data. That data could exist pretty much anywhere on a worksheet, but we can perhaps assume that it starts in the top left cell, cell A1, and the headings are in row 1, in cells A1 and B1. That said, only recently, someone wanted a Dynamic Named Range that appeared (from the formula quoted) to start in cell A1. In reality, it started in cell F190. Easy mistake, yes?

    You've provided an excerpt of your code, splitting it into three sections so it becomes a chore to copy. It doesn't have a Sub or End Sub, it doesn't define the variables, it doesn't indicate where the variables have values set, for example, the workbook name and the value of the variable "i". There's no indication of what you want/need to do with the value when you get it.

    I don't know if you use Option Explicit to ensure that all variables are defined, but I do because it avoids typing mistakes, etc.

    So, as I said,for me to test your code, I need to create a workbook; I need to copy the data from your next post into it; I need to use Text to Columns to split the data into columns A and B. For convenience, I then put a SUMIF formula into the worksheet to check the value I expect to get from the code.

    That's before I even look at the code. I need to copy the three sections and paste them into a module with an empty Subroutine. I need to comment out the explanations that you have provided about what works and what doesn't. Then I have to define all the variables correctly and, where possible, set the values of the variables so the code will run. At that point, I have a workbook with some data and some code in it ... that runs and produces a value.

    What I don't have is a workbook with code in it that opens another workbook with data in it and then calculates a value.

    Hopefully, that explains my frustration.

    The working code, which does not open a second workbook and which uses data within the macro enabled workbook is listed below.

    Please Login or Register  to view this content.

    Please see the attached workbook. You may be able to adapt this to meet your needs.

    Regards, TMS
    Attached Files Attached Files
    Last edited by TMS; 07-23-2014 at 04:47 PM.

  9. #9
    Registered User
    Join Date
    07-23-2014
    Location
    Napoli
    MS-Off Ver
    Office 2010
    Posts
    6

    Re: [VBA] SUMIF coding problem with a file

    thanks TMS for you very important help. Your code is correct but mine is a bit different and has an error again.

    I try to post the code that i have used so i hope the problem will be more clear

    I try to attach the sheet "summay". I remember that "My Sheet" is on an other different file.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: [VBA] SUMIF coding problem with a file

    The problem appears to be that it doesn't like doing a SUMIF in a separate instance of Excel. Removing the Excel_app fixes the problem. ScreenUpdating = False masks the opening of the Summary workbook in the same instance.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-23-2014
    Location
    Napoli
    MS-Off Ver
    Office 2010
    Posts
    6

    Re: [VBA] SUMIF coding problem with a file

    Hello TMS, the code works fine and it's ok but i have an other question.
    I have tow files

    1. a file with che code above
    2. a file from with i want work with sumif.

    I want to store the result "list_sums(i)" into the sheet "summary" that is in the file where the code is. The sumif results is the result of an other file.

    Redars,

    Lestat2204

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,251

    Re: [VBA] SUMIF coding problem with a file

    The original question has been answered. You should mark this solved and start a new thread.

    The current code updates the summary sheet in the workbook you navigate to.

    You need to post sample workbooks which accurately reflect your requirements.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to correct my combined SumIf and SumProduct calculation in macro coding
    By cmwilbur in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-22-2011, 04:54 PM
  2. VBA coding a nested Vlookup, and a sumif formula
    By Xrull in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2009, 02:07 PM
  3. If, Then, Else Coding Problem
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-30-2006, 03:30 PM
  4. [SOLVED] Please help: Coding Problem
    By Tim in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-28-2005, 01:05 AM
  5. Coding problem
    By John in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2005, 01:05 PM

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