Cartillo
asked on
Allow multiple data entry in a single cell
Hi Experts,
I would like to request Experts help to add an additional feature in the attached script. The script is being used to copy data from Booking Sheet (Title – Cell C5) into Order Sheet based on information at Start/End Date, Start/End Time and the frequency (condition). Total data (Title) that need to copy at Order sheet is determined based on the number that was entered in Frequency cell (C11).
The current limitation with this code is, the code enables booking after the end date & time whenever no other valid options have been found. E.g. (Please refer the attached Workbook at “Order Sheet”) Title C is being booked for 1st and 2nd Jan at 06:00 to 10:00 with frequency 20. By right, this title needs to be copied between this date/time. Since there isn’t any other valid option, the balance of the data automatically copied at 3rd Jan, which is outside of booking date. Is that any possibilities the macro should be able to segregate the balance of the data between 1st and 2nd (date/time) by allowing multiple entries in the cells? E.g. Cell, B5 and C9 have shared Title C (two data in a single cell).
Hope Experts will help me to create this feature.
I would like to request Experts help to add an additional feature in the attached script. The script is being used to copy data from Booking Sheet (Title – Cell C5) into Order Sheet based on information at Start/End Date, Start/End Time and the frequency (condition). Total data (Title) that need to copy at Order sheet is determined based on the number that was entered in Frequency cell (C11).
The current limitation with this code is, the code enables booking after the end date & time whenever no other valid options have been found. E.g. (Please refer the attached Workbook at “Order Sheet”) Title C is being booked for 1st and 2nd Jan at 06:00 to 10:00 with frequency 20. By right, this title needs to be copied between this date/time. Since there isn’t any other valid option, the balance of the data automatically copied at 3rd Jan, which is outside of booking date. Is that any possibilities the macro should be able to segregate the balance of the data between 1st and 2nd (date/time) by allowing multiple entries in the cells? E.g. Cell, B5 and C9 have shared Title C (two data in a single cell).
Hope Experts will help me to create this feature.
Sub spreaddatatest()
Dim start_date As Date
Dim start_time As Date
Dim end_date As Date
Dim end_time As Date
Dim booking_date As Date
Dim booking_time As Date
Dim duration As Date
Dim gap As Date
Dim number_of_days As Integer
Dim frequency As Integer
Dim booking As Integer
Dim booking_column As Integer
Dim booking_row As Integer
Dim last_booking_row As Integer
Dim result
With Sheets("Booking")
'-- initialise
start_date = CDate(.[c7])
end_date = CDate(.[e7])
start_time = CDate(.[c9])
end_time = CDate(.[e9])
'-- before 6 o'clock = next day
If start_time < TimeValue("06:00:00") Then start_time = start_time + 1
If end_time < TimeValue("06:00:00") Then end_time = end_time + 1
If end_time < start_time Then MsgBox ("Starting time is higher that ending time"): End
'-- calculate time span
number_of_days = end_date - start_date + 1
duration = (end_time - start_time) * number_of_days - 0.00001
frequency = .[c11]
If frequency > 1 Then gap = duration / frequency
End With
booking_date = start_date
booking_time = start_time
For booking = 1 To frequency
'-- locate booking position
booking_column = Sheets("Order").Range("2:2").Find(booking_date).Column
booking_row = (booking_time - TimeValue("6:00:00")) * 24 * 6 + 3
'-- prevent double bookings where possible
last_booking_row = Sheets("Order").Range("A:A").Find(what:=end_time - WorksheetFunction.Floor(end_time, 1), lookat:=xlWhole).Row
While Sheets("Order").Cells(booking_row, booking_column) <> ""
booking_row = booking_row + 1
If booking_row > last_booking_row Then
booking_column = booking_column + 1
booking_row = Sheets("order").Range("A:A").Find(what:=start_time, lookat:=xlWhole).Row
End If
Wend
'-- add booking to orders
Sheets("Order").Cells(booking_row, booking_column) = Sheets("Order").Cells(booking_row, booking_column) & vbCrLf & Sheets("Booking").[c5]
'-- determine next booking
booking_time = booking_time + gap
While booking_time > end_time
booking_date = booking_date + 1
booking_time = booking_time - end_time + start_time
Wend
Next booking
End Sub
OrderList-V3.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi akoster,
Thanks for the revised scripts. Now it's able to add multiple data in a single cell. The only part is even though the data were separated evenly, but the timing needs to adjust. I have manually copied sample data in the attached workbook ( please refer "Sample" sheet) for better view. Is that possible copy the data diagonally instead of horizontal? This is to prevent the sample title being seen at the same time on the next day.
OrderList-V3.xlsm
Thanks for the revised scripts. Now it's able to add multiple data in a single cell. The only part is even though the data were separated evenly, but the timing needs to adjust. I have manually copied sample data in the attached workbook ( please refer "Sample" sheet) for better view. Is that possible copy the data diagonally instead of horizontal? This is to prevent the sample title being seen at the same time on the next day.
OrderList-V3.xlsm
ASKER
Hi akoster,
Is there any possibility to copy the data diagonally?
Is there any possibility to copy the data diagonally?
ASKER
Hi akoster,
Please let me know if you need additional info from my side.
Please let me know if you need additional info from my side.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi akoster,
This code just nice for placing a booking. The only obstacle that I have now with this code is its copied multiple titles in single line. I have attached the sample data for your perusal (e.g.. Please refer cell C4, C15, D36). How to prevent this?
OrderList-V3.xlsm
This code just nice for placing a booking. The only obstacle that I have now with this code is its copied multiple titles in single line. I have attached the sample data for your perusal (e.g.. Please refer cell C4, C15, D36). How to prevent this?
OrderList-V3.xlsm
This can be prevented by replacing the line
with
Apperantly the join statement does not take into account the carriage return/line feed characters.
Sheets("Order").Cells(current_row, current_column) = Join(bookings)
with
current_booking_slot = ""
For pos = 1 To UBound(bookings)
current_booking_slot = current_booking_slot & vbCrLf & bookings(pos)
Next pos
Sheets("Order").Cells(current_row, current_column) = current_booking_slot
Apperantly the join statement does not take into account the carriage return/line feed characters.
ASKER
Hi,
What does it means by "does not take into account the carriage return/line feed characters"?
What does it means by "does not take into account the carriage return/line feed characters"?
Akoster, the join function has an optional second argument which can take VbCr.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Thanks a lot for the help
Thanks a lot for the help
you're welcome !
ASKER
The first option should be find, hope you will consider to add this feature in this code.