简体   繁体   中英

Vba for each cell in range

I need help with the following

  • Cells b6:b76 Contain True/False formula to show when if i should do the action each month
  • Cells c6:c76 contain file paths for the object i want to embed
  • Cells n6:c76 is the destination where i want the object to be

I the vba to to go down column b checking whcih cell contains True and then for each cell contain true Dim file path as and then insert an object and display as icon in column N with Column d as label

Any Help would be most Appreciated

I have tried

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

i Have now tried this but there is a error when defining what the path is

Sub insert()

Dim R As Integer

Dim path As String

For R = 6 To 76

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

**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

Next R

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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