VBA를 Google Apps Script로 변환

스티브 K

아래에 VBA 코드가 있습니다. 어떻게 작동하는지 모르겠지만 Google 스프레드 시트로 변환하고 싶습니다.

누군가가 다음 중 하나를 수행 할 수 있기를 바랍니다.

  • VBA가 수행하는 작업을 설명하여 Google Apps 스크립트로 프로그래밍 할 수 있도록 충분히 추론 할 수 있도록합니다.

또는

  • Google 스프레드 시트를 통해 동일한 VBA 기능을 어떻게 얻을 수 있는지 보여주세요.


Function getData(targetName As String, targetSheet As String, targetDate)
Application.Volatile True
Dim res As Double
Dim col As Integer
Dim cell As Range
Dim names As Range

Dim lastrow As Long

With ThisWorkbook.Worksheets(targetSheet)
    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    col = Application.Match(targetDate, .Range("4:4"), 0)
    If col = 0 Then
        getData = CVErr(xlErrNA)
        Exit Function
    End If
    Set names = .Range(.Cells(4, "A"), .Cells(lastrow, "A"))

    For Each cell In names
        If cell = targetName Then
            res = res + cell.Offset(, col - 1)
        End If
    Next cell
End With

getData = res
End Function

다음은 함수가 사용되는 예제 Excel 파일에 대한 링크입니다. https://www.dropbox.com/s/h5vcjv9tlh1vvg7/Resources%20and%20Projects%20Full%20Example.xlsm

바로 그거죠

Google Apps 스크립팅에 익숙하지 않지만 첫 번째 부분에서는 도움을 드릴 수 있습니다.

함수의 요점은 nameA 열 에서 찾은 항목 targetName이 매개 변수로 전달 date되고 행 4 에서 찾은 항목 이 매개 변수 인 일치 하는 모든 값을 합산하는 것으로 보입니다 targetDate. (행은로 결정되고 name열은로 결정됩니다 date.) 그러면 총 값이 double.

다음은 한 줄 주석입니다.

Function getData(targetName As String, targetSheet As String, targetDate)
Application.Volatile True 'I don't see a reason for this line
Dim res As Double
Dim col As Integer
Dim cell As Range
Dim names As Range

Dim lastrow As Long

With ThisWorkbook.Worksheets(targetSheet) 'All ranges start with ThisWorkbook.'targetSheet'
    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row 'Get the last row with data in column A to 'lastrow'
    col = Application.Match(targetDate, .Range("4:4"), 0) 'Find 'targetDate' in row 4 and set it to 'col'
    If col = 0 Then 'Couldn't find 'targetDate'
        getData = CVErr(xlErrNA) 'Function returns the appropriate error
        Exit Function 'Exit the function after setting the return value
    End If
    Set names = .Range(.Cells(4, "A"), .Cells(lastrow, "A")) 'Setting the range from A4 to A'lastrow' to 'names'

    For Each cell In names 'Looping through every 'cell' in the 'names' range
        If cell = targetName Then 'If the 'cell' value matches the 'targetName' passed in as a parameter
            res = res + cell.Offset(, col - 1) 'Add the value from the column with the 'targetDate' to 'res'
        End If
    Next cell
End With

getData = res 'Return the total
End Function

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

JSON 문자열 날짜를 자바 스크립트로 변환 (Google Apps Script)

분류에서Dev

Google Apps Script에서 문서를 문자열로 어떻게 변환합니까?

분류에서Dev

Google Apps Script-UrlFetch 응답을 배열로 변환

분류에서Dev

Google Apps Script UrlFetchApp.fetch는 정수를 부동 소수점으로 변환합니까?

분류에서Dev

Google Spreadsheet Apps Script에서 셀 참조를 문자열로 변환하는 방법은 무엇입니까?

분류에서Dev

.gs (Google Apps Script)의 데이터를 html의 <script> 변수로 공유

분류에서Dev

Google Apps Script 변수로서의 HTML href

분류에서Dev

Google Apps Script, 텍스트를 하이퍼 링크로 반환하는 기능

분류에서Dev

Google Apps Script에서 Blob으로 변환 할 때 .xlsx 파일이 손상됨

분류에서Dev

한 Google-Apps-Script에서 다른 Google-Apps-Script로 매개 변수를 전달하고 실행하는 방법은 무엇입니까?

분류에서Dev

Google Apps Script를 사용하여 플랫 JSON 배열을 중첩 된 JSON으로 변환하는 방법은 무엇입니까?

분류에서Dev

Google Apps Script에서 참조로 함수 간 변수 전달

분류에서Dev

Google Apps Script 변수로 HTML 입력 미리 채우기

분류에서Dev

Google Apps Script는 프로젝트 속성에서 시간대를 변경할 수 없습니다.

분류에서Dev

Google Apps Script에서 배열 반환

분류에서Dev

Google Apps Script에서 null 값 반환

분류에서Dev

Google Apps Script ----> numberLong을 날짜 형식으로 변환 (예 : 2015-12-02T16 : 51 : 31 + 00 : 00)

분류에서Dev

Node.JS 코드 스 니펫을 자바 스크립트 (Google Apps Script)로 변환

분류에서Dev

Google Apps Script가 '제한 초과 : URLFetch URL 길이'오류를 반환합니다.

분류에서Dev

HTMLService / Google Apps Script에서 날짜 선택기를 사용하여 값 반환

분류에서Dev

Google Apps Script를 통해 Chrome 탭 열기

분류에서Dev

Google Apps Script를 사용하여 지정된 Meet URL로 Google 캘린더 이벤트를 생성 / 변경하려면 어떻게합니까?

분류에서Dev

Google-apps-script SyntaxError

분류에서Dev

Google Apps Script 호출

분류에서Dev

여러 매개 변수로 기능을 실행하는 Google Apps Script Make 버튼

분류에서Dev

Google Apps Script를 사용하여 query.setquery를 현재 날짜로

분류에서Dev

Google Apps Script를 사용하여 Google 양식에서 URL 매개 변수를 어떻게 얻습니까?

분류에서Dev

Apps Script를 사용하여 Google 문서 도구의 기본 단락 제목을 프로그래밍 방식으로 변경

분류에서Dev

ajax에서 Google Apps Script로 값 전달

Related 관련 기사

  1. 1

    JSON 문자열 날짜를 자바 스크립트로 변환 (Google Apps Script)

  2. 2

    Google Apps Script에서 문서를 문자열로 어떻게 변환합니까?

  3. 3

    Google Apps Script-UrlFetch 응답을 배열로 변환

  4. 4

    Google Apps Script UrlFetchApp.fetch는 정수를 부동 소수점으로 변환합니까?

  5. 5

    Google Spreadsheet Apps Script에서 셀 참조를 문자열로 변환하는 방법은 무엇입니까?

  6. 6

    .gs (Google Apps Script)의 데이터를 html의 <script> 변수로 공유

  7. 7

    Google Apps Script 변수로서의 HTML href

  8. 8

    Google Apps Script, 텍스트를 하이퍼 링크로 반환하는 기능

  9. 9

    Google Apps Script에서 Blob으로 변환 할 때 .xlsx 파일이 손상됨

  10. 10

    한 Google-Apps-Script에서 다른 Google-Apps-Script로 매개 변수를 전달하고 실행하는 방법은 무엇입니까?

  11. 11

    Google Apps Script를 사용하여 플랫 JSON 배열을 중첩 된 JSON으로 변환하는 방법은 무엇입니까?

  12. 12

    Google Apps Script에서 참조로 함수 간 변수 전달

  13. 13

    Google Apps Script 변수로 HTML 입력 미리 채우기

  14. 14

    Google Apps Script는 프로젝트 속성에서 시간대를 변경할 수 없습니다.

  15. 15

    Google Apps Script에서 배열 반환

  16. 16

    Google Apps Script에서 null 값 반환

  17. 17

    Google Apps Script ----> numberLong을 날짜 형식으로 변환 (예 : 2015-12-02T16 : 51 : 31 + 00 : 00)

  18. 18

    Node.JS 코드 스 니펫을 자바 스크립트 (Google Apps Script)로 변환

  19. 19

    Google Apps Script가 '제한 초과 : URLFetch URL 길이'오류를 반환합니다.

  20. 20

    HTMLService / Google Apps Script에서 날짜 선택기를 사용하여 값 반환

  21. 21

    Google Apps Script를 통해 Chrome 탭 열기

  22. 22

    Google Apps Script를 사용하여 지정된 Meet URL로 Google 캘린더 이벤트를 생성 / 변경하려면 어떻게합니까?

  23. 23

    Google-apps-script SyntaxError

  24. 24

    Google Apps Script 호출

  25. 25

    여러 매개 변수로 기능을 실행하는 Google Apps Script Make 버튼

  26. 26

    Google Apps Script를 사용하여 query.setquery를 현재 날짜로

  27. 27

    Google Apps Script를 사용하여 Google 양식에서 URL 매개 변수를 어떻게 얻습니까?

  28. 28

    Apps Script를 사용하여 Google 문서 도구의 기본 단락 제목을 프로그래밍 방식으로 변경

  29. 29

    ajax에서 Google Apps Script로 값 전달

뜨겁다태그

보관