Are you looking for an answer using R? It is certainly possible to load excel data into R, perform calculations and reshaping in R, and save the output back into Excel, but I'm not sure if that's what you want.
There are a few steps involved here, each of which has many tutorials online.
Here's some fake data:
df <- data.frame(patient = c(1, 1, 1, 2, 3),
date = seq.Date(as.Date("2020-12-01"), by = -1, length.out = 5),
diagnosis = LETTERS[1:5])
patient date diagnosis
1 1 2020-12-05 A
2 1 2020-12-04 B
3 1 2020-12-03 C
4 2 2020-12-02 D
5 3 2020-12-01 E
Assuming you first install R, install RStudio, install the tidyverse package, and load the excel data in, you could run this R code to reshape the table. This says that, "start from the data frame we've saved called df, then (ie %>%) group the data by patient, then arrange the data by patient and date, then add a variable called visit_number that records which row we're on within each patient, then ungroup the data, then reshape it to a wider shape using the visit_number as the column name, prefixed with visit_, and using the diagnosis and date as the data.
library(tidyverse)
df %>%
group_by(patient) %>%
arrange(patient, date) %>%
mutate(visit_number = row_number()) %>%
ungroup() %>%
pivot_wider(names_from = visit_number,
names_prefix = "visit_",
values_from = c(diagnosis, date))
That produces, which I think is getting towards what you're looking for.
# A tibble: 3 x 7
patient diagnosis_visit_1 diagnosis_visit_2 diagnosis_visit_3 date_visit_1 date_visit_2 date_visit_3
<dbl> <chr> <chr> <chr> <date> <date> <date>
1 1 C B A 2020-12-03 2020-12-04 2020-12-05
2 2 D NA NA 2020-12-02 NA NA
3 3 E NA NA 2020-12-01 NA NA
Then you could save to excel.
It's a bunch of steps, but all of them individually are well documented online.