+ Reply to Thread
Results 1 to 10 of 10

writing a "script"

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Post writing a "script"

    i want to do a:

    foreach (i = 50,i++,i=1)
    {
    if column B value = "surname"
    {
    sum column C value

    }
    }

    i have this but im sure it is completely wrong LOL

    function myFunction() {

    //var myDoc = SpreadsheetApp.getActiveSpreadsheet("Client Billing");
    //var app = UiApp.createApplication().setTitle('Loots');

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("HS");
    var lastRow = sheet.getLastRow();
    var range = sheet.getRange(2,1,lastRow,7);
    var values = range.getValues();
    var data = range.getValues();
    var newsheet = SpreadsheetApp.create("loots", 50, 3);
    Logger.log(newsheet.getUrl());


    for (i in data)
    {
    var row = data[i];
    var date = row[0];
    var client = row[1];
    var activity = row[2];
    var rate = row[6];
    if (client = "loots")
    {
    row[410] = rate;
    //newsheet[i,1] = date;
    //newsheet[i,2] = activity;
    //newsheet[i,3] = rate;
    }
    }
    }
    please help?

    thanks

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: writing a "script"

    That's JavaScipt, are you making a 2013 app for office?

  3. #3
    Registered User
    Join Date
    04-11-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: writing a "script"

    nope i just want to write a little "program" that can do the foreach and the if within
    ive never done it so dont know where to start

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: writing a "script"

    In that case you're going to need to give us more to go on:
    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  5. #5
    Registered User
    Join Date
    04-11-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: writing a "script"

    here some sample data

    sample data.JPG

    say i want to loop through column B "Client"
    if it contains the value for example "le roux"
    write to a new sheet column A, B, C H

    ex:

    new sheet data.JPG

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: writing a "script"

    We need a workbook...

  7. #7
    Registered User
    Join Date
    04-11-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: writing a "script"

    i attached the workbook
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Hi ! Try this !


    Paste this code to Sheet1 worksheet module :

    PHP Code: 
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As RangeCancel As Boolean)
        
    With Target
            
    If .Column And .Row And .Value "" Then
                Cancel 
    True
                
    If Sheet2.UsedRange.Count 4 Then Union([A1:C1], [H1]).Copy Sheet2.Cells(1)
                
    Cells(2).Copy Sheet2.Cells(11):  .Copy Sheet2.[K2]
                
    Cells(1).CurrentRegion.AdvancedFilter xlFilterCopySheet2.[K1:K2], Sheet2.[A1:D1]

                
    With Sheet2
                    
    .[K1:K2].Clear
                    With 
    .Cells(1).CurrentRegion:  .WrapText False:  .Columns.AutoFit:  End With
                    
    .Activate
                End With
            End 
    If
        
    End With
    End Sub 
    Just double click on a client name …

    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 07-13-2015 at 10:53 PM. Reason: optimization …

  9. #9
    Registered User
    Join Date
    04-11-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Hi ! Try this !

    nooo thats way to complicated, sorry

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: writing a "gas factory" code




    When you will know Excel basics and VBA, you may understand that way maybe as easiest and fastest !
    Last edited by Marc L; 07-15-2015 at 06:21 AM.

+ 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. Script not copying data from "Emails" sheet to "New Sheet" - Run time error: Object
    By methuselah90 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2014, 03:22 PM
  2. [SOLVED] Script to save to folder in "v:\dept2", confirm file saved, then delete from "v:\dept1"
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2014, 11:42 AM
  3. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  4. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  5. Writing a formula in a macro. How do I define the range as "start to end?"
    By ChrisF79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2013, 02:58 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