본문 바로가기
GAS

[GAS] VBA 기초방 #9 [ 데이터 영역 선택하기 ]

by 일등미노왕국 2023. 1. 8.

 

function haja_gas_1() {
  const sht = SpreadsheetApp.getActiveSheet();          // 시트설정
  const cell = sht.getRange("b2:c8").getValues();       // 순환할 영역 설정
  let rngX = sht.getRange("f2");                        // 출력할 영역의 초기값
  sht.getRange("g2:k8").clearContent                    // 기존 출력한 영역 초기화  
          
      cell.forEach(ele=>{

      const C = ele[1];   
      rngX.offset(0,C).setValue(ele[0]);               // 상수 C 만큼 offset하여 각 배열의 두번째 값을 출력
      rngX = rngX.offset(1,0);
      })
  
}

 

 

function haja_gas_2() {
    const sh = SpreadsheetApp.getActiveSheet();        // 시트 설정
    const cel = sh.getRange("b14:c24").getValues();    // [b14:c24] 영역의 값을 cel 배열에 넣어라
    let rngA = sh.getRange("f14");                     // 값들을 출력할 첫 위치

    sh.getRange("f14:k100").clearContent               // 영역 초기화
            
        cel.forEach(ele=>{                             // 순환문

          rngA.setValue(ele[0]);                       // 성명값을 출력
          rngA.offset(0,1).setValue(ele[1]);           // 중복값을 출력

          const R = ele[1];                            // 변수 R에 중복값 삽입
          rngA = rngA.offset(1+R,0);                   // 변수 R만큼 줄바꿈 해라
      
          })
 // 현재는 정확한 데이터 영역에만 정렬과 테두리를 만드는 법을 알지 못해서 임의의 영역 [f14:g100] 으로 설정
                                                  
  sh.getRange("f14:g100").setHorizontalAlignment("center");           // 가운데 정렬 
  sh.getRange("f14:g100").setBorder(true,true,true,true,true,true);   // 테두리 설정
}

아직 뭔가 낯설고 불편하지만 VBA처럼 언젠간 꼭 정복하리라

'GAS' 카테고리의 다른 글

[GAS] sheets데이터를 html 문서를 작성해보자  (0) 2023.04.19
[GAS] 중복없는 로또번호 만들기  (0) 2023.04.17
[GAS] 시트 통합 && 필터링  (0) 2023.04.04
[GAS] 시트통합 매크로  (0) 2023.04.03
[GAS] `I'm ${name}`  (0) 2022.12.27

댓글