2017-12-14 1 views
0

일치하는 경우 : Google 애플리케이션 스크립트를 사용하여Google 시트 - 시트 2의 데이터로 업데이트 시트 1 두 시트의 값이 나는이 하나 개의 스프레드 시트에 시트가

https://docs.google.com/spreadsheets/d/1ahtB9M6rl6aHmj51ZlP_qDqyUwhpsSVg1r16BafcKIo/edit?usp=sharing

, 나는의 값을 업데이트 할 각 시트의 ID 열의 값이 일치하는 경우 "새 데이터"시트의 열 E 값과 함께 "보고서"시트의 열 C를 선택합니다.

프로덕션에서는 여러 개의 고유 한 일치가있을 것으로 예상됩니다. 어떻게하면 좋을까요?

아래의 모의 시트에서 행 ID가 12 인 보고서 시트의 "상태"열의 값을 "대기 중"에서 "원"으로 업데이트하고 싶습니다.

  • 보고서 시트

    ID | 상태

    12 | 대기열

    34 | |

  • 새 데이터 시트

    ID

    분실 상태

    56 | 분실했습니다

    12 | 원

+0

멋진 프로젝트입니다. 뭔가에 대해 궁금한 점이 있으면 알려주십시오. –

+0

안녕 앙투안, 고마워! 내가 명시 적으로 질문하지 않았다는 것을 깨달았습니다. 이 일을 가장 잘 수행하는 방법을 찾고 싶습니다. 몇 가지 방법을 시도했지만 아무 소용이 없습니다. –

+0

이봐, 나는 당신이 downvotes을 받고 있다고보고, 여기 [더 나은 질문을하는 방법에 대한 안내] (http://catb.org/~esr/faqs/smart-questions.html)입니다. 스택 오버플로 및 기타 장소에 적용됩니다. –

답변

0

이번 주에 질문 된 내용은 similar question입니다.

시트와 제목의 이름을 변경해야하지만 여기에 제 제안이 있습니다.

function setCommon() { 

    var ss = SpreadsheetApp.getActive(), 
     compare1 = "", compare2 = "", 

     outputSheet = ss.getSheetByName("Sheet1"), 
     sourceSheet = ss.getSheetByName("Sheet2"), 

     range1 = outputSheet.getDataRange(), 
     range2 = sourceSheet.getDataRange(), 

     lastCol1 = range1.getNumColumns(), 
     lastCol2 = range2.getNumColumns(), 

     values1 = range1.getValues(), 
     values2 = range2.getValues(), 

     // get the range of the titles 
     titleSection1 = outputSheet.getRange(1,1,1, lastCol1), 
     titleSection2 = sourceSheet.getRange(1,1,1, lastCol2), 

     // get the values from the titles 
     titles1 = titleSection1.getValues(), 
     titles2 = titleSection2.getValues(), 

     // get the column # for "ID" and "comment" 
     idCol1 = titles1[0].indexOf("ID"), 
     idCol2 = titles2[0].indexOf("ID"), 
     commentsCol1 = titles1[0].indexOf("comment"), 
     commentsCol2 = titles2[0].indexOf("comment"); 

    // get the IDs from range1 
    for (i = 1; i < values1.length; i++) { 
    compare1 = values1[i][idCol1]; 

    // get the IDs from range2 
    for (j = 1; j< values2.length; j++){ 
     compare2 = values2[j][idCol2]; 

     // if same ID, change the values array 
     if (compare1 == compare2) { 
     values1[i][commentsCol1] = values2[j][commentsCol2]; 
     } 
    } 
    } 
    // set values based on the values array 
    range1.setValues(values1); 
} 
+0

이 앙투안을 가져 주셔서 감사합니다! 귀하의 도움을 많이 주시면 감사하겠습니다. 나는 그것을 줄 것이다! –

+0

방금 ​​시도해 보았습니다! 고마워요! –

관련 문제