Excel VBA copy data from one workbook to another & running macro number of times based on a cell value

HEALTHSTAFF

New Member
Joined
Oct 5, 2017
Messages
12
Hello,
I have two workbooks one is for making bookings and a second that has a list of numbers allocated to vouchers.
Workbook one has data like surname, date of appointment & staff initials. I want this data transferred to workbook 2 which is where we allocate voucher numbers to clients. The second workbook(which would be closed) has 4 columns Voucher number, surname, appointment date and staff initials. Voucher numbers are already listed in the worksheet. I have two lots of code I have cobbled together (sort of a noob). I would like the data added to workbook 2 based on a cell value in workbook 1. eg if the client needed 2 vouchers the name & details would be added to workbook 2 twice one line under the other in column "B" It has some errors which i thought a guru may be able to look at for me. I know some of the code is lengthy and could be done faster. Its getting stuck at the paste data stage.
Many Thanks
Workbook 1 Part 1
Code:
Sub Bluebuttonpress()
   printbluecabsign
   Dim y As Workbook
             
   Dim i As Long
    For i = 1 To ThisWorkbook.Worksheets("FRONT SHEET").Range("C17").Value
           Call datacabcharge
    Next
End Sub

Second Part Workbook 1
Code:
Sub datacabcharge()
Dim y As Workbook
Dim NextRow As Range
'## Open both workbooks first:
Set x = ThisWorkbook
Set y = Workbooks.Open("W:\WACHS-GS\Blah\departments\Medical Records Department\MR New\MR STAFF\Craig\Craig PATS\Cabcharge registerXXXX.xlsm")
   
'Now, copy what you want from x:
Workbooks("AAA PATIENT BOOKING TEMPLATE XXXX - Rex Flights.xlsm").Activate
Worksheets("FRONT SHEET").Range("E37:G37").Copy
Workbooks("Cabcharge registerXXXX.xlsm").Activate
Dim lastrow As Long
lastrow = Range("B" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.Cells(lastrow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
y.Save
y.Close


End Sub
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,215,541
Messages
6,125,413
Members
449,223
Latest member
Narrian

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top