Facing issue with for each loop in excel VBA

Hi,
I am using VBA .
I am looping through each row and the column matches value,I am getting the value of  G column with the selected row.
      Dim selectedCell As Range
        Dim weekMinutes As Double
        Dim rowNumber As Integer
        usageTracking.Activate
        weeklySheetName = sheetName
         For Each selectedCell In ActiveSheet.Range("A:A")
          If selectedCell.Value = customerName Then
    '          weekMinutes = ActiveSheet.Range("G" & (selectedCell.row)).Value
               weekMinutes = Cells(selectedCell.row, "G").Value
    End If
      Next selectedCell
I am able to get value for the first row.
from second row,even though i am having different value,the "weekMinutes" value is showing as 0 instead of the value in the cell.
whats wrong I am doing.

Hi AjayChigurupati,
The code seems ok, and I also made a quick test. It works well for me.
Please check the value in A column, the weekMinutes variable only was assigned when the value in column A is equal customerName.
I also suggest that you loop the UsedRange in Column A to improve the preformance.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Custom List with for-each loop

    How do I get a list I am making to be able to be used with a for-each loop?

    As far as I know there is no "for-each" loop in Java, there is however a "for" loop. Is that what you're referring to?
    To use a for loop, let's say you have an array like the following, you could iterate through it like this:
    String[] str = new String[]{"a", "b", "c", "d", "e"};
    for (int i = 0; i < str.length; i++)
             System.out.println(str);
    hope this help you get started ;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Issue with Reading data with FOR EACH LOOP.

    Hi Guys,
    Scenario
    We Plan Sales of an Article on a half years(fiscal variant MQ with 2 periods of half year each). We also plan the
    number of Weeks in Sales as a Key figure.  The cummulative Sales for two half years in then distributed to number of weeks for which the Article is sold (0CALWEEK)
    In another Cube we plan a distribution profile. This cube contains just three elements.
    Characteristic = ZPROFILE
    TIme Char = 0CALWEEK
    Keyfigure = ZDIST
    (Note : You will notice The distribution profile is not stored per Article here)
    The logic of distribution is :
    1.  Sales of Article is cummulated for 1 years ( eg. for periods 001.2010 & 002.2010 )
    2.  Find the number of weeks in Sales for this Article ( eg. 14 weeks. ) [Technically we store this value on the first fiscal
    period. In our example it is stored in 001.2010
    3.  User choose a distribution profile in a variable ( e.g ZH55 )
    4   ZDIST is summed for number of Sale Weeks for this Article. in our case it is14 weeks.
    5. Distribution = Sales of Article (WEEK N) = [Sales Cummulated for 1 year] * [ZDIST(Week N) / ZDIST(sum of 24 weeks)]
    This loop is run 14 times. (N from 201001 to 201014.)
    TECHICAL DETAILS
    Cube 1 (0CM_SKU = Material, 0CPBAINSABU = SALES key figure, WEEKINSALE = Number of weeks for which Material will be
    sold). The Sales Planned data is stored as # for 0CALWEEK.
    0CM_SKU/0CALWEEK/0FISCPER/0FISCVARNT/0CPBAINSABU--/WEEKINSALE
    SHIRT/000000/2010001/ZP/100EUR--/24
    SHIRT/000000/2010002/ZP/200EUR--/00
    PANTS/000000/2010001/ZP/300EUR--/35
    PANTS/000000/2010002/ZP/200EUR--/00
    CUBE 2 ( the profile data is stored here )
    ZPROFILE/0CALWEEK/ZDIST
    ZH55/201001/10
    ZH55/201002/12
    ZH55/201003/8
    ZH55/201004/11
    ZH55/201005/10
    ..so on.
    9:11 PM
    Edited by: Dheeraj Gupta on Apr 5, 2010 9:20 PM

    My Sample CODE IS BELOW.
    DATA CW1 TYPE 0CALWEEK.
    DATA CW2 TYPE 0CALWEEK.
    DATA PER1 TYPE 0FISCPER.
    DATA PER2 TYPE 0FISCPER.
    DATA FVAR TYPE 0FISCVARNT.
    DATA PROV1 TYPE 0INFOPROV.
    DATA PROV2 TYPE 0INFOPROV.
    DATA SKU TYPE 0CM_SKU.
    DATA DPROF TYPE ZPROFILE.
    DATA CUMSALES TYPE F.
    DATA TEMP TYPE F.
    DATA PRO TYPE F.
    DATA COUNT TYPE I.
    *I WILL READ THE PROFILE VALUE FROM VARIABLE IN ACTUAL PROGRAM.
    HARDCODED FOR TEST PURPOSES. 
    DPROF = 'ZH55'.
    *FISCAL YR VARIANT
    FVAR = 'MQ'.
    *HARDCODED FOR TEST PURPOSES. 
    PER1 = 2010001.
    PER2 = TMVL(PER1, 1, FVAR).
    *CUBE FOR SALES
    PROV1 = 'ZCLARK'.
    *CUBE FOR PROFILE
    PROV2 = 'C_ZCLARK'.
    FOREACH SKU.
    *SUM UP SALES FOR ONE YEAR
    *Operand:{Key figure name, 0CALWEEK, 0CM_SKU, 0FISCPER, 0FISCVARNT, 0INFOPROV, ZPROFILE}
    CUMSALES = CUMSALES + {0CPBAINSABU,#,SKU,PER1, FVAR,PROV1,#} + {0CPBAINSABU,#,SKU,PER2, FVAR,PROV1,#}.
    *READ NUMBER OF WEEKS OF SALES
    COUNT = {ZNWEEK,#,SKU,PER1, FVAR,PROV1,#}.
    *HARDCODED FOR TEST PURPOSES. 
    Starting week of distrbution is first week of the year
    CW2 = 201001.
    CW1 = 201001.
    *HELP NEEDED HERE ***********
    *NOT ABLE TO READ THIS PROFILE DATA
    DO COUNT TIMES.
       PRO = PRO + {ZPROF,CW2,#,#,#,PROV2,ZPROFILE}.
       CW2 = TMVL(CW2, 1).
    ENDDO.
    DO COUNT TIMES.
    {0CPBAINSABU,CW1,SKU,#, #,PROV1,#} = CUMSALES * {ZPROF,CW1,#,#, #,PROV2,ZPROFILE} / PRO.
    CW1 = TMVL(CW1, 1).
    ENDDO.
    *RESET
    CUMSALES = 0.
    ENDFOR.

  • For Each Loop: Truncation error on excel field

    In my SSIS package, I'm using a WMI file watcher combined with a ForEach loop to process excel files and load them into a SQL Server database as they are deposited in a drop box folder. Recently I've been getting truncation errors on one of my fields (Comments).
    I know that this is because Excel is scanning the first 8 rows to determine column length and there are several records that have a comments field that is greater than what excel determined.
    I've tried going to the excel editor in my advanced editor and setting the data type length of my external and output columns to a larger length (500 W_STR vs 255 W_STR) but I get a warning saying that the data type is not valid. I've tried adding IMEX=1
    to my extended properties in my excel connection string but no dice. Still getting truncation errors.
    I was wondering if anyone had any thoughts or suggestions? I'm always getting new files so the comments field will potentially always encounter this type of error. This SSIS package runs on a production server so making a Registry change to the excel drivers
    regarding the scanning of the first 8 rows is not an option for me.
    Migince

    I wound up making the registry change for # of rows scanned by excel and that seemed to solve the issue.
    I tried utilizing an excel template but every time my for each loop scanned for a new file, the metadata was updated with whatever column length was in the first 8 records of my new file. If you've got a good example of building an excel template to set
    the column length metadata in my excel source (For Each Loop) I would love to take a look at it. Good information to know.

  • For Each Loop Load Dynamic Excel Files

    Hi All,
    SSIS 2005
    I want to load excel file .xls one at a time files that have different names without having to select the file in the connection manager, every time. So a user can easily place the excel file in the folder and right the sql job and it loads the file data.
    The data flow tasks all work when I manually select the excel file, but I am unable to get this to work dynamically.
    I have setup a for each loop with multiples data flow tasks and sql tasks to load my data from file.
    Variables:
    @filename d:\new file\*.xls
    For Each Loop:
    ForEachFile Enumerator
    Folder: d:\new file\
    Files: *.xls
    Retrieve File Name: Fully Qualified
    Variable Mappings:
    User::filename (index 0)
    Connection Managers:
    Excel Connection Manager: Expressions, ConnectionString @[User::filename]
    Error Message: Error at new buyer(package name) the connection string format is not valid. it must consist of one or more components of the form X=Y, seperated by semicolons.
    Can anyone assist thanks.

    You still need the file name variable.
    ExcelFilePath is the fully qualified file name of your Excel file. ie. it contains both the path and file name.
    e.g. D:\inbox\myExcelFile.xls
    All the steps you mentioned are correct, except you need to set the property of ExcelFilePath of the Excel connection to the variable that you map to in the ForEach Loop:
    Connection Managers:
    Excel Connection Manager: Expressions, ExcelFilePath @[User::filename]
    Hope this helps.
    ~ J.

  • SQL Agent Permssions With SSIS for each loop not looping through files

    Hi I am Having trouble getting a ssis package to iterate through a file directory using a proxy account set up in Sql Server.
    So I have a package that loops over csv files. If I run the package manually or set the sql agent job to run as Sysadmin the pakage runs fine all files are processed.
    However if I use the proxy account. the package completes but no files are processed. there are no failures, there is no error handling set up in the control flow. the for each loop container simply does not recognise any files when run under a proxy.
    Note: the proxy is set up with credentials to access the folder. the credential is also set up with the server admin server role... still nothing
    i'm not sure is this is a ssis or permissions problem?
    Any comments will be appreciated

    Can you check this and see if you've configured all the steps correctly
    http://www.mssqltips.com/sqlservertip/2163/running-a-ssis-package-from-sql-server-agent-using-a-proxy-account/
    Also enable logging in package and see if you're getting any error messages obtained in output table/file based on the logging option you chose.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Excel Sheet Looping: For each loop from variable Enumerator

    Hi,
    Is it possible to do excel sheets looping using For each loop Enumerator as "For Each loop from Variable enumerator" ? If yes, please help.
    Also,
    I have an excel file with 10 sheets, but want to loop only 5 sheets. Please help..how can i achieve this. 
    Actually i tried with
    1> stored the 5 sheets name into a variable (say 'SheetsName') of type string using script task
    2> For each loop container
       enumerator - 'For each ADO Schema Rowset enumerator'
       connection: ADO
       schema: 'Tables'
       variable mapping: 'User::SheetsName'
    3> Within For each loop container added a data flow task
    4> Inside DFT - excel source - 
       Data access Mode: 'Table Name or view name variable'
       Variable Name: 'SheetsName'
    but this loops through all the 10 sheets irrespective of only 5 sheets names stored in the variable "SheetsName".
    Please help...
    Please Mark as Answer if my post solved your problem or Vote As Helpful if this helps. Blogs: www.sqlserver2005forum.blogspot.com

    >> Is it possible to do excel sheets looping using For each loop Enumerator as "For Each loop from Variable enumerator" ? If yes, please help.
    I don't think so. To loop through all worksheets of Excel For ADO.NET Schema Rowset Enumerator is the only option.
    Please refer:
    https://msdn.microsoft.com/en-us/library/ms345182(v=sql.110).aspx
    >> I have an excel file with 10 sheets, but want to loop only 5 sheets
    So you have configured For Each loop container which loops throgh all sheets and returns you sheet name to variable "SheetName".
    Drag and drop one Sequence Container inside ForEach Loop Container and connect it to Data Flow Task.
    Right click on connector and use expression: (which will check if current sheet is one of 5 required sheets)
    @User::SheetName == "FirstSheet" ||  @User::SheetName == "SecondSheet" || .....
    Below blog demonstrates kind of simillar steps:
    http://www.bidn.com/blogs/MikeDavis/ssis/559/ssis-skip-certain-files-in-a-for-each-loop 
    -Vaibhav Chaudhari

  • For Each Loop Issue In SSIS

    Hi All,
    I have a SSIS Package which unzips the folder and then imports the files and then moves *.zip folders into processed location. If this task is executed as a part of total package its not moving the *.zip folders into processed location, but when we execute
    for each loop alone this *.zip folders are moved into processed location. I am unable to figure out the issue here.
    ZippedFile variable holds fully qualified file name..
    Rohan
    Rohan

    Can you put a OnPreExec breakpoint on the file system task (Right click on the file system task > Edit Breakpoint... > Select the first (OnPreExec breakpoint) and when the pkg pauses @ the breakpoint, chk the value of the ZippedFle and FilePathDestination
    variable values in your Local window (should be available at the bottom of the SSIS window as one of the tabs and you will need to expand the variable tree and find these two variables and their values). Are you seeing the appropriate values here?

  • Single row table with for-each group loop to set variable.

    Hi: There is probably a simple answer for this but I have not found it ...
    I have a single row table to loop through a group to set a variable holding a running amount. I am not displaying the amount within the table however when I preview the report I see that the table is expanding (adding rows) for each loop.
    The single row table has 3 columns.
    1st column
    <?for-each:AC_GROUP?>
    2nd column
    <?xdoxslt:set_variable($_XDOCTX,'xAmtVar',xdoxslt:get_variable($_XDOCTX,'xAmtVar')+CURRENT_AMOUNT)?>
    3rd column
    <?end for-each?>
    Should I be using <?for each-group?> or something else. My requirement is to set the value of the variable with the running total but because the loop is adding rows for each value it loops through (even though not displayed), it is moving other areas of the layout off the page.
    Hope this makes sense. Thanks in advance.

    you can do it many ways.
    No need to loop
    You can create a variable and put the sum amount directly in that.
    <?doxslt:get_variable($_XDOCTX,'xAmtVar',sum(/AC_GROUP/CURRENT_AMOUNT))?>or
    loop thru and add like you do.
    <?for-each@inlines:AC_GROUP?><?xdoxslt:set_variable($_XDOCTX,'xAmtVar',xdoxslt:get_variable($_XDOCTX,'xAmtVar')+CURRENT_AMOUNT)?><?end for-each?>do give any space or enter character in word between them, just put this in a single form-field will do
    But as i said, i would certainly go with first option.

  • Get the Excel file creatoin Date through For Each Loop each excel file in SSIS

    I had  For Each Loop
    in Collection Path had 2 files it had Creation date of 25/01/2014
    So I want Update in Table that date as File_Receive_Date column
    How Can I do ??
    in variable I am using VFile_FULL_Name(=Filename with Path by attach to Foreach loop collection&connection manager)
    which other System Variable to use in SSIS  ??
    I have created vRef_Date  but in Expression =====??? what should I do through only SSIS ??
    Thanks
    Madhu

    The easiest approach is https://filepropertiestask.codeplex.com/ can capture the file creation date, but it is not working for all SSIS versions
    I recommend using .net FILE IO libraries to get the created date which needs to be done in a Script Task.
    The ForLoop approach will not let you achieve this goal.
    Arthur
    MyBlog
    Twitter

  • For each loop with multidimensional arrays?

    Hi.I have a problem with for each and multidimensional combination.
    public class TestCards
    static int[][] dizi={{1,2},{3,4}};
    static int t ;
    public static void main(String[]args)
         for (int[] i : dizi)
         System.out.println(i);
    The result of the codes above is like this
    [I@9304b1
    [I@190d11
    In other words the result is now integer.It has some strange chars which i dont know
    Pls help me !

    You're printing an array. Arrays don't override toString.
    - You could iterate over both dimensions and print each value yourself.
    - You could iterate over one dimension and call java.util.Arrays.toString to print a row at a time.*
    - You could call java.util.Arrays.deepToString to print the entire thing in one shot.
    *The second option is closest to what you're doing now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SSIS Help For each Loop Container

    I need a little help with this process that I am developing. I am fairly new to SSIS so please bear with me. I have done research online so If I seem limited in my knowledge please apologize me.
    Requirement: I have a folder where we will have flat files monthly they could be one or more...
    each file will have the following name standard "123456.EEAKQ2.EASDREWA12A.BID".
    What I need to do is maintain a table which will have filename and date when it was added to the folder.
    I have created a package with the following components "For each loop" which grabs files from a source folder.
    This is where I am stuck. I need to grab the file name from the path and insert it into the table.
    Can someone help me with this?
    Thank you
    FM
    FM

    See similar requirement implemented here
    What you need is to declare and use a variable inside for each loop to get filename each time. Then you may use script task to check for pattern within the file for identifying correct files
    http://visakhm.blogspot.in/2012/05/package-to-implement-daily-processing.html
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • For each loop start on odd page number

    Hy,
    I've an rtf template with a for each loop. I want to skip a page between each loop and to start each new loop on an odd page number (duplex printing). It's easy to skip a page but i don't know how to start each loop on an odd page. i've tried this before or after my for-each
    <?section:force-page-count;'end-on-even-layout'?>
    but it doesn't work for me.
    Sorry for my english
    regards

    One way of doing this is to create an object (B_1) at the end of the report and only have the object print if the current page is an odd page.
    - To force the page break, you need to set the "page break before" property against "B_1".
    - To test the page number in the format trigger use the srw.get_page_num(page_num out number) built-in function.
    You need to make sure that "B_1" is formatted after all the other objects in the layout. One way of ensuring this is to create a frame around all the other objects and make the frame variable. Any objects that come below the frame will be formatted after the variable frame.
    There is still the issue of any margin objects. Since margin objects print before any objects in the body, your margin objects will still print in the overflow page. However, this may be what you want if you're printing the page number in the margin.

  • For each loop container executing multiple times....

    Hi,
    We are using SQL SERVER version 2005.
    I am having a For each loop container and inside that container there are multiple Sequence containers and inside each sequence containers there are Execute SQL Tasks (which are just stored procedures).
    Now, when i run sequence containers individually they are running perfectly fine.
    But when I run the whole For each loop container, it is just running and running multiple times without ending the process.
    I really couldnt figure out what would be the issue?
    Any ideas????
    Thanks....

    Hi grk666,
    To check whether the values stored in the object type variable are correct, you can disable all the Sequence Containers within the Foreach Loop Container, and add a Script Task with the following code to display the string type variable value (supposing
    you use the string type variable StrVar to store the value retrieved from the object variable):
    MsgBox(Dts.Variables(“StrVar”).Value.ToString())
    It would be helpful if you could post a screenshot to show the package execution at runtime in BIDS.
    Regards,
    Mike Yin
    TechNet Community Support

  • How to use for each loop in XSLT when my source is a multilayout file and db

    How do I use a for each loop in XSLT when my source is multilayout file and db .
    My multilayout file is basically contain 2 kind of data one for employee and another for dependent.
    Now my requirement is I want to read each line of data whether it is it is employee or dependent do a join with db and write it in my target file.
    eg :  File content
    1 RichaKumari 311289 TCS INDIA
    2 KiarnKumar 456782 BRO RichaKumari 311289 INDIA
    2 Ravi            456882 BRO RichaKumari 311289 INDIA
    eg : db Content
    311289 RichaKumari TCS INDIA Bangalore [email protected]
    Now in Final File I need something like this :
    1 RichaKumari 311289 TCS INDIA
    2 KiarnKumar RichaKumari 311289 TCS INDIA
    2 Ravi            RichaKumari 311289 TCS INDIA
    here 1 and 2 are the identifier which will decide which layout to follow .

    Hi,
    I think you'll need two nested for-each's... Something like...
    <xsl:for-each select="$root/row[layout = 1]">
    <xsl:variable name="employee" select="."/>
    ... write employee ...
    <xsl:for-each select="$root/row[layout = 2 and dependentid = $employee/id]">
    ... write dependent ...
    </xsl:for-each>
    </xsl:for-each>
    Cheers,
    Vlad

Maybe you are looking for

  • How do i select multiple cells in numbers or iPad?

    Hello, can you help me? I do not find out how to select multiple cells in a table that do not stand next to each other. For example, I want to select cells A1, A3, A9 and so on. Afterwards I want to change the colour. Do you have an idea? Perhaps it'

  • How can I add new photos to a saved photobook?

    I've started a photobook and saved it. All the pictures that were in the filmstrip but not placed in pages in the book are gone from the project. How can I add them back?

  • Need help creating creating a webservice as per the documentation

    I'm trying to setup a webservice with reliable messaging using the NWDS. I'm trying to follow the example given in http://help.sap.com/saphelp_nw72/helpdata/en/46/741a3dfcfa0eede10000000a155369/content.htm I'm not familiar with J2EE development, so I

  • Optimal use of many resource

    Hi Folks My System: OS: linux OEL 5.2 x86_64 Memory: 112GB CPU: 4*6Core = 24Cores Filesystem: ASM 11.1.0.7 RDBMS: Oracle 11.1.0.7 Archivelogmode We have recently migrated an OLTP Database (~1.3TB) to this server above. It is a Single Instance DB and

  • IPhone calendar not syn in icloud

    When I input new event from my iphone and ipad, the new event don't syn to iCloud!!!