Prompt Title: 계량오차검사 ver0.1

Created 1 year ago
Votes 0
Views 178 times
0
Human: vba로 코드 작성해보자 내가 말로 하면 넌 코드로 작성해줘 pb2의 시트에 데이터가 있다 슈퍼출력 시트의 3행 2열에 있는 데이터를 pb2 시트의 h열에서 모두 찾는거야 이 데이터가 들어있는 행의 데이터중에 내가 필요한 데이터를 배열에 집어 넣을거야 1. e 2. c 3. d 4. g 5. be 6. bf 7. bb 8. az 9. ba 10. cq셀의 데이터중 좌측으로부터 3번째부터 5번째까지의 문자 11. ac셀 데이터 + ad셀 데이터중에 ad셀의 데이터의 비율 12. bh 13. z 14. aa 15.ab 16. w 17. x 18. t 19. ac 20. ad 21. af ag ah ai 중에 0이 아닌 숫자가 있는 셀의 값
ChatGPT:

먼저, VBA를 사용하여 말씀하신대로 코드를 작성해 드리겠습니다.

vba
Option Explicit Sub FindDataAndCollect() Dim wsSource As Worksheet, wsTarget As Worksheet Dim TargetCell As Range, FoundCell As Range Dim DataArray() As Variant Dim LastRow As Long, i As Long, j As Long Set wsSource = ThisWorkbook.Worksheets("pb2") Set wsTarget = ThisWorkbook.Worksheets("슈퍼출력") Set TargetCell = wsTarget.Cells(3, 2) LastRow = wsSource.Cells(wsSource.Rows.Count, "H").End(xlUp).Row ReDim DataArray(1 To LastRow, 1 To 21) For i = 1 To LastRow If wsSource.Cells(i, "H").Value = TargetCell.Value Then DataArray(j, 1) = wsSource.Cells(i, "E").Value DataArray(j, 2) = wsSource.Cells(i, "C").Value DataArray(j, 3) = wsSource.Cells(i, "D").Value DataArray(j, 4) = wsSource.Cells(i, "G").Value DataArray(j, 5) = wsSource.Cells(i, "BE").Value DataArray(j, 6) = wsSource.Cells(i, "BF").Value DataArray(j, 7) = wsSource.Cells(i, "BB").Value DataArray(j, 8) = wsSource.Cells(i, "AZ").Value DataArray(j, 9) = wsSource.Cells(i, "BA").Value DataArray(j, 10) = Mid(wsSource.Cells(i, "CQ").Value, 3, 3) DataArray(j, 11) = wsSource.Cells(i, "AC").Value + (wsSource.Cells(i, "AD").Value / 100) DataArray(j, 12) = wsSource.Cells(i, "BH").Value DataArray(j, 13) = wsSource.Cells(i, "Z").Value DataArray(j, 14) = wsSource.Cells(i, "AA").Value DataArray(j, 15) = wsSource.Cells(i, "AB").Value DataArray(j, 16) = wsSource.Cells(i, "W").Value DataArray(j, 17) = wsSource.Cells(i, "X").Value DataArray(j, 18) = wsSource.Cells(i, "T").Value DataArray(j, 19) = wsSource.Cells(i, "AC").Value DataArray(j, 20) = wsSource.Cells(i, "AD").Value For Each FoundCell In wsSource.Range("AF" & i & ":AI" & i) If FoundCell.Value <> 0 Then DataArray(j, 21) = FoundCell.Value Exit For End If Next FoundCell j = j + 1 End If Next i End Sub

위 코드는 말씀하신대로 슈퍼출력 시트의 3행 2열에 있는 데이터를 pb2 시트의 H열에서 찾아 지정된 셀들의 값을 배열에 저장합니다. 이후에 배열에 저장된 값을 사용하여 원하는 작업을 수행하실

avatar
durian0606
Shared 1 prompt
Created 1 year ago

Leave a Comment