范围内每个细胞的Vba

时间:2017-12-11 15:52:59

标签: excel vba if-statement next

我需要以下

的帮助
  • 单元格b6:b76包含真/假公式,以显示我应该何时执行操作 每个月
  • 单元格c6:c76包含要嵌入的对象的文件路径
  • 单元格n6:c76是我希望对象
  • 的目的地

我vba要向下列b检查whcih单元格包含True然后为每个单元格包含真正的Dim文件路径,然后插入一个对象并在列N中显示为图标,其中列d为标签

任何帮助都会得到最多的赞赏

我试过了

Sub insert()


Dim rng As Range
Dim Ref As Boolean
Dim cell As Variant

Set rng = Range("b6:b76")


For Each cell In rng

    Ref = cell.Value

    If Ref = True Then


    Dim path As String
    path = ActiveCell.Offset(0, 1).Value

    ActiveCell.Offset(0, 12).Select
    ActiveSheet.OLEObjects.Add(Filename:=path _
         , Link:=False, DisplayAsIcon _
        :=True, IconFileName:= _
        "C:\Windows\Installer\{AC76BA86-7AD7-1033-7B44-AA1000000001}\PDFFile_8.ico", _
        IconIndex:=0, IconLabel:="Column d????"). _
        Select
    ActiveSheet.Shapes("Object 19").IncrementLeft 11.25
    ActiveSheet.Shapes("Object 19").IncrementTop 36
Next

End Sub

1 个答案:

答案 0 :(得分:0)

我现在尝试了这个,但在定义路径

时出错

子插入()

Dim R As Integer

Dim path As String

对于R = 6到76

If Cells(R,2).Value =" True"然后

**Error Is Here** path = Cells(R, 3).Value

Cells(R, 12).Select
ActiveSheet.OLEObjects.Add(Filename:=path _
     , Link:=False, DisplayAsIcon _
    :=True, IconFileName:= _
    "C:\Windows\Installer\{AC76BA86-7AD7-1033-7B44-AA1000000001}\PDFFile_8.ico", _
    IconIndex:=0, IconLabel:="column d value ??"). _
    Select
ActiveSheet.Shapes("Object 19").IncrementLeft 11.25
ActiveSheet.Shapes("Object 19").IncrementTop 36

End If

下一个R

End Sub