26. maj 2012 - 22:43Der er
4 kommentarer og 1 løsning
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Jeg kan ikke få dette til at køre på samme ark. hvad er fejlen
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim shpTemp As Shape, lTop As Long, lTeft As Long, lWidth As Long, lHeight As Long If Target.Address = "$A$14" Then lTop = Range("b14").Top lleft = Range("b14").Left lWidth = 200 lHeight = 155 ActiveSheet.Pictures.Delete sti = ThisWorkbook.Path
Select Case Target Case Is = 1, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\1.gif", True, False, lleft, lTop, lWidth, lHeight) Case Is = 2, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\2.gif", True, False, lleft, lTop, lWidth, lHeight) Case Else Exit Sub End Select Set shpTemp = Nothing End If End Sub
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim shpTemp As Shape, lTop As Long, lTeft As Long, lWidth As Long, lHeight As Long If Target.Address = "$b$7" Then lTop = Range("E7").Top lleft = Range("E7").Left lWidth = 200 lHeight = 155 ActiveSheet.Pictures.Delete sti = ThisWorkbook.Path
Select Case Target Case Is = 1 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\H.gif", True, False, lleft, lTop, lWidth, lHeight) Case Is = 2 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\V.gif", True, False, lleft, lTop, lWidth, lHeight) Case Else Exit Sub End Select Set shpTemp = Nothing End If End Sub
deu kan ikke have 2 sub's af samme navn, koden skal samles i en.
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim shpTemp As Shape, lTop As Long, lTeft As Long, lWidth As Long, lHeight As Long If Target.Address = "$A$14" Then lTop = Range("b14").Top lleft = Range("b14").Left lWidth = 200 lHeight = 155 ActiveSheet.Pictures.Delete sti = ThisWorkbook.Path
Select Case Target Case Is = 1, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\1.gif", True, False, lleft, lTop, lWidth, lHeight) Case Is = 2, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\2.gif", True, False, lleft, lTop, lWidth, lHeight) Case Else Exit Sub End Select Set shpTemp = Nothing End If
If Target.Address = "$b$7" Then lTop = Range("E7").Top lleft = Range("E7").Left lWidth = 200 lHeight = 155 ActiveSheet.Pictures.Delete sti = ThisWorkbook.Path
Select Case Target Case Is = 1 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\H.gif", True, False, lleft, lTop, lWidth, lHeight) Case Is = 2 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\V.gif", True, False, lleft, lTop, lWidth, lHeight) Case Else Exit Sub End Select Set shpTemp = Nothing End If End Sub
ja det virker nu men jeg kan ikke få begge billeder op på samme ark på samme tid jeg har ændret range til som nedenstående.
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim shpTemp As Shape, lTop As Long, lTeft As Long, lWidth As Long, lHeight As Long If Target.Address = "$A$14" Then lTop = Range("b14").Top lleft = Range("b27").Left lWidth = 200 lHeight = 155 ActiveSheet.Pictures.Delete sti = ThisWorkbook.Path
Select Case Target Case Is = 1, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\1.gif", True, False, lleft, lTop, lWidth, lHeight) Case Is = 2, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\2.gif", True, False, lleft, lTop, lWidth, lHeight) Case Else Exit Sub End Select Set shpTemp = Nothing End If
If Target.Address = "$B$7" Then lTop = Range("d7").Top lleft = Range("d7").Left lWidth = 200 lHeight = 155 ActiveSheet.Pictures.Delete sti = ThisWorkbook.Path
Select Case Target Case Is = 1, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\1.gif", True, False, lleft, lTop, lWidth, lHeight) Case Is = 2, 0 Set shpTemp = ActiveSheet.Shapes.AddPicture(sti & "\2.gif", True, False, lleft, lTop, lWidth, lHeight) Case Else Exit Sub End Select Set shpTemp = Nothing End If End Sub
jeg har fundet ud af hvordan jeg får begge billeder på samme side jeg har slettet ActiveSheet.Pictures.Delete i den sidste
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.