以下Excel工作表所需的VBA Excel偏移公式

问题描述 投票:0回答:1

请找到下面的 Excel 工作表图像。我需要

VBA
代码。

enter image description here

结果应该是

enter image description here

A 列与 b、c、d、e、f、g 之后组合。只需带“YES”字样即可,“NO”则无需。

excel vba database macros offset
1个回答
0
投票

如果您想仅通过VBA实现,这里是VBA代码。

这是源示例图像

并且是来自同一张纸的目标图像。

Sub TransposeAndFill()
'Declare variables
Dim ws As Worksheet
Dim i As Long
Dim j As Long
Dim r As Long
Dim src As Range
Dim dst As Range

'Set worksheet and ranges
Set ws = ActiveSheet
Set src = ws.Range("A1:G12") 'Source range
Set dst = ws.Range("I1:K1") 'Destination range

'Copy headers
ws.Range("I1").Value = ws.Range("A1").Value
ws.Range("J1").Value = "Seq"
ws.Range("K1").Value = "Result"

'Initialize row counter for destination range
k = 2

'Loop through columns of source range (except first column)
For i = 2 To src.Columns.Count
    'Loop through rows of source range (except first row)
    For j = 2 To src.Rows.Count
        'Copy site value from first column
        dst.Cells(k, 1).Value = src.Cells(j, 1).Value
        'Copy seq value from column header
        dst.Cells(k, 2).Value = src.Cells(1, i).Value
        'Copy result value from cell
        dst.Cells(k, 3).Value = src.Cells(j, i).Value
        'Increment row counter for destination range
        k = k + 1
    Next j
    'k = k + 1
Next i

结束子

© www.soinside.com 2019 - 2024. All rights reserved.