bartvt78
Gebruiker
- Lid geworden
- 16 mrt 2017
- Berichten
- 255
- Besturingssysteem
- Mac OS en Windows Parallels
- Office versie
- Office 365
Goedemiddag collega forumleden. Ik zit momenteel met een probleem. Ik heb met behulp van ChatGPT volgende VBA geschreven. Als ik deze test, met stap voor stap functie in VBA werkt deze perfect. Maar als ik deze wil laten lopen met een drukknop in excel, werkt deze niet. Verder wil ik ook op het laatste beide sheets beveiligen, maar op WsTarget moet er in kolom AI een hyperlink worden toegevoegd (manueel, nadat het script beëindigd is) Als ik de sheet gewoon beveilig, kan er nadien geen hyperlink meer ingevoegd worden. En voor dit laatste stukje laat ChatGPT me dus in de steek. Ik hoop dat onderstaande code genoeg is, daar de hele file nogal groot is. Hartelijk dank voor mee te denken.
Mvg,
Bart
Mvg,
Bart
Code:
Sub Buy_Copy()
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim pasteCell As Range
Set wsSource = ActiveSheet
Set wsTarget = ThisWorkbook.Worksheets("Trades Advanced")
wsSource.Unprotect Password:="Test"
'Copy source cells
wsSource.Range("B8").Copy
'Go to Trades Advanced and use the selected cell as destination
wsTarget.Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(0, 1).Select
'Copy source cells
wsSource.Activate
wsSource.Range("C8").Copy
'Go to Trades Advanced and use the selected cell as destination
wsTarget.Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(0, 6).Select
'Copy source cells
wsSource.Activate
wsSource.Range("D8").Copy
'Go to Trades Advanced and use the selected cell as destination
wsTarget.Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(0, 1).Select
'Copy source cells
wsSource.Activate
wsSource.Range("E8").Copy
'Go to Trades Advanced and use the selected cell as destination
wsTarget.Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.Offset(0, 2).Select
'Copy source cells
wsSource.Activate
wsSource.Range("I8").Copy
'Go to Trades Advanced and use the selected cell as destination
wsTarget.Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Select target sheet at the end
wsTarget.Activate
End Sub