请找到下面的 Excel 工作表图像。我需要
VBA
代码。
结果应该是
。
A 列与 b、c、d、e、f、g 之后组合。只需带“YES”字样即可,“NO”则无需。
如果您想仅通过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
结束子