leighmetcalfe
New Member
- Joined
- Oct 27, 2012
- Messages
- 46
I currently have the below macro to copy data from a my sales workbook and paste the values to a closed workbook.
I'm struggling to find a macro that can check column C of the closed workbook for "VE01", if this appears then delete the line and run the transfervalues sub
This is to prevent duplicate entries.
I'm struggling to find a macro that can check column C of the closed workbook for "VE01", if this appears then delete the line and run the transfervalues sub
This is to prevent duplicate entries.
Code:
Sub TransferValues()
Application.ScreenUpdating = False
Dim wsMain As Worksheet
Dim wbData As Workbook
Dim wsData As Worksheet
Dim rngToCopy As Range
Dim C As Long
Dim ar As Range
Dim cl As Range
Dim Lastrow As Long
Dim rngDestination As Range
Set wsMain = ThisWorkbook.Sheets("Enquiry Ticket")
Application.DisplayAlerts = False
' you need to open the workbook
Set wbData = Workbooks.Open("T:\Sales\Sales\Test.xlsb")
Set wsData = wbData.Sheets("C&B")
Set rngToCopy = wsMain.Range("A3:AI3")
'Get the last row in Database sheet:
Lastrow = wsData.Cells(wsData.Rows.Count, "A").End(xlUp).Row
C = 1
For Each cl In rngToCopy
cl.Copy
wsData.Cells(Lastrow + 1, C).PasteSpecial xlPasteValues
C = C + 1
Next cl
wbData.Close True '<-- close and save the changes made
Application.DisplayAlerts = True '<-- restore settings
Application.ScreenUpdating = True
End Sub