繁体   English   中英

复制并粘贴在黄色突出显示的行下方

[英]Copy and paste below the yellow highlighted row

不知道这是否有可能,但是可以解决。 我对这个vba代码感到停滞不前。 我尝试附加图片示例-不知道它是否可以正确显示。

一切都是蓝色字体,我创建了一个vba代码,可以直接从顶部几行开始复制它

1)我需要一个宏,该宏将在标题行1的所有单元格中查找“连续类型”,如果它在其中找到任何单元格,则在黄色突出显示的行正下方的同一列中(在这种情况下,该行5,但可能会更改,因为数据每天都会更新),在“ Finance”一词中加上“ Finance”一词必须向下直到与A列中的行数匹配。

单击链接以查看我要完成的示例

您需要使用循环来执行此操作。 所以像这样:

x = 1 'the starting column to look for content type
Do While cells(1, x) <> "" 'look in every column until your columns are empty
If Cells(1, x) = "Cont Type" Then
Range(Cells(6, x), Cells(n, x)) = "Finance" 'With n equaling your last column to insert this to
Else
End If
x = x + 1 'go to the next column to look
Loop

尝试:

Option Explicit

Sub test()

    Dim LastColumn As Long, i As Long

    'Change sheet name if needed
    With ThisWorkbook.Worksheets("Sheet1")
        'Find LastColumn of row 1
        LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column

        'Loop Cells of the first row
        For i = 1 To LastColumn

            'If cells in row 1 and column i is "Cont Type"
            If .Cells(1, i).Value = "Cont Type" Then
                'Import in range
                .Range(.Cells(6, i), .Cells(9, i)).Value = "Finance"
            End If

        Next i

    End With

End Sub

结果:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM