Extract the date and name and repeat it along the column

sofas

Active Member
Joined
Sep 11, 2022
Messages
480
Office Version
  1. 2019
Platform
  1. Windows
Hello. I want help extracting the name of the product from column C, provided there is the word "Restaurant*") The date from the H column
And it is repeated along the column down to the second condition so that it is extracted and repeated in the same way. The problem is that I used this code, it does a good job, but it is very slow, because the file consists of hundreds of rows and invoices, and it always extracts names and dates from the first invoice, even though it is not empty. Can I modify it and help me in another code that does the same task, but it starts when it finds the invoice is empty

Screenshot_3.png


VBA Code:
Sub Remplir_tout_all()
Dim nmax&, a$(), derlig&, tablo, i&, n&, C As Range, dat$, h&
Dim rng As Range
Set ST = Sheet1
 lr = ST.Range("a" & Rows.Count).End(xlUp).Row
With Sheet1
    nmax = Application.CountIf(.[c:c], "Restaurant*")
    ReDim a(nmax)
    derlig = .Range("C" & .Rows.Count).End(xlUp).Row + 1
    a(nmax) = "c" & derlig
    tablo = .Range("c1:c" & derlig)
    For i = 1 To derlig
        If Trim(tablo(i, 1)) Like "Restaurant*" Then a(n) = "c" & i: n = n + 1
    Next i
    Application.ScreenUpdating = False
     Range("a4:b" & lr).ClearContents
    .[A:B].HorizontalAlignment = xlCenter
    For n = 0 To UBound(a) - 1
        Set C = .Range(a(n))
        dat = Mid(Trim(C(5, 6)), 11, 10)
        h = .Range(a(n + 1)).Row - 1 - C(5).Row
        If h > 0 Then
            If IsDate(dat) Then C(6, -1).Resize(h) = CDate(dat)
            C(6, -0).Resize(h) = C(2)
        End If
    Next n
End With
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I didn't get what the code does quite. But it seems, first you loop through column C to collect ranges including "Restaurant" then you are looping again with the collection to do something else. You are looping twice even if the second loop has less range to process.

Isn't it possible to complete what you want to do within the first loop? "If restaurant found, then do something.."
 
Upvote 0
Can you show us what your example data looked like BEFORE column A and B were filled in? I'm trying to get a sense of the spacing of the unprocessed data (your date range in Column H seems to be haphazardly placed with respect to the restaurant names in Column C. Also, I am trying to figure out if the row spacing for the output already exists or if blank rows have to be inserted to accommodate the output.
 
Upvote 0
Can you show us what your example data looked like BEFORE column A and B were filled in? I'm trying to get a sense of the spacing of the unprocessed data (your date range in Column H seems to be haphazardly placed with respect to the restaurant names in Column C. Also, I am trying to figure out if the row spacing for the output already exists or if blank rows have to be inserted to accommodate the output.
Hello. Thank you for your attention. This is a picture of the file format. And a similar copy like that you might want to take a look at. But the original file consists of hundreds of rows. My problem is that it always fills in the data from the first invoice even though it contains the dates

Screenshot_2.png
 
Upvote 0
Please send a file via wetransfer. I am begging you...
Prepare a file with sample data with cinema names, for instance and fake revenues. Please issue two sheets, one with the starting state and on with the end result state. Otherwise it is very difficult for me to understand something from empty colums.
 
Upvote 0
This is an example of the original file replica. The only difference is that the number of rows can reach hundreds of rows. The attached code in the post works well. The problem is that it always fills in a column
A:B From the first row, even if it has dates. Which causes a great slowdown in execution, up to several minutes, which is required to start from the first empty table
Please send a file via wetransfer. I am begging you...
Prepare a file with sample data with cinema names, for instance and fake revenues. Please issue two sheets, one with the starting state and on with the end result state. Otherwise it is very difficult for me to understand something from empty colums.
 
Upvote 0
Ok, Now I understand. One question. Do you have any dates like: From Date 12/01/2023/ To Date 13/01/2023?

If yes, then how it starts and how it ends? How many days will be 12 and how many days will be 13?
 
Upvote 0
This is an example of the original file replica. The only difference is that the number of rows can reach hundreds of rows. The attached code in the post works well. The problem is that it always fills in a column
A:B From the first row, even if it has dates. Which causes a great slowdown in execution, up to several minutes, which is required to start from the first empty table
Please send a file via wetransfer. I am begging you...
Prepare a file with sample data with cinema names, for instance and fake revenues. Please issue two sheets, one with the starting state and on with the end result state. Otherwise it is very difficult for me to understand something from empty colums.
This is an example of the original file replica. The only difference is that the number of rows can reach hundreds of rows. The attached code in the post works well. The problem is that it always fills in a column


 
Upvote 0

Forum statistics

Threads
1,215,527
Messages
6,125,336
Members
449,218
Latest member
Excel Master

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