For context, I have minor coding experience, but I am completely new to VBA and am improvising on the go. I am aware that I will not be creating the most optimal code and thankfully I don’t need to be, as this is not a tech focused job.
I am working on creating a visualiser for my work rota, where it reads the start and end times for everybody scheduled (located in column C of the same worksheet) and creates an output like the image attached.
a visual schedule of a day going horizontally, where 1 box across is equal to 1 hour (there are 4 cells per box)
I will do my best to explain how I intend for this to work, apologies if it’s confusing:
-
The program reads the start_time of each person from the input section in column C.
-
As they are custom times, the values are as fractions (e.g. 11am is 11/24 which equals ~0.458333, 7:30am is 7.5/24 = 0.3125).
-
I then want to find the corresponding time on the visualiser headings in range N2:CS2, which are also custom times.
-
I have attempted to use .Find to achieve this, but it is not finding a match in the given range even though I know the two values are identical.
-
I have tried many different formats of .Find, such as having ‘What:=’ or omitting it, having the additional parameters or trying with just the default settings, having ‘with Range(“N2:CS2”)’ instead of ‘Range().Find’ and nothing has worked.
-
I have checked, and the values of start_time are definitely equal to the values of the visualiser headings, so I don’t understand why .Find is saying there’s no match.
For row_number = 6 To 100 Step 2
' For each of the staff listed on input section,
If Not IsEmpty(Range("C" & row_number)) Then
' If they have a start time on Monday then,
Dim start_time As String
start_time = Range("C" & row_number).Value
' Make note of their start time,
Dim rFind As Range
Set rFind = Range("N2:CS2").Find(start_time, SearchOrder:=xlByColumns, SearchDirection:=xlNext)
' And in the visualiser time headers, find the header that matches the start time.
Next
I have condensed the code as there are elements that I don’t think are relevant. If needed, I can send a complete screenshot of everything in the sub as well as what the input area looks like.
Thank you for reading.
detra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1