VBA - Matching specific date horizontally and insert value

minhlac

New Member
Joined
Jul 25, 2018
Messages
6
Hi all,

I found this forum very helpful so I sign up and this is my first post in this forum. :)

Please help! I have data as below, date from column D will keep going to the right (as a diary record).


ABCDEFGHIJ
1ItemQuantityDelivery date04/0805/0806/0807/0808/0809/0810/08
2red207/082
3blue
4yellow
5pink509/085

<tbody>
</tbody>




I would like to have a solution with Excel VBA carry out two tasks

1. For the example above, for item "red" when input delivery date and quantity then it will scan through row 2 for a matching date and leave the quantity at the intersecting cell of the same row looking up to that date column. Therefore we have the result 2 in cell "G2". In general, VBA will look up value (date format) in column C to match value (also date format) of any column from D onward, find the intersecting cell of the value current row and matched date column, then pick up value in column B (same row) and to insert in intersecting cell.

2. The intersecting cell value will stay as "text" only without formula format since column B and C will be dynamic changes based on user input.

I hope that would make sense.
Thank you in advance for your time.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
hope this works

Code:
Sub mrexcelmatchdatetest1()

Dim i As Integer
Dim datecol As Integer
Dim lastrow As Integer

lastrow = Range("A1").End(xlDown).Row

For i = 2 To lastrow
    
    If Range("C" & i) <> "" Then
        datecol = Application.WorksheetFunction.Match(Range("C" & i), Rows(1), 0)
        
        Cells(i, datecol).Value = Range("B" & i).Value
    Else
    
    End If

Next i

End Sub
 
Upvote 0
Hi fhqwgads,

your code works fine with column C manually text input, when I replace with a formula to calculate delivery date and it reset all the date on column C to 02/01/1900. Would you have a look again to modify the previous code.

Thank you.
 
Upvote 0
hmm not sure what went wrong
what exactly are you putting in column C before running the sub?
 
Upvote 0
Hi fhqwgads ,

Initially, Column C was text input (manually).

Now, Column C (in date format) = ETA date + Today() ~~~> where
ETA date is another column retrieved from another worksheet.

So Column C values are now formulated instead of text input...This is when your previous code call an error because it reset all the value (in date format back to 02/01/1900). Even though I tried to change the date format to number it won't work.

Thank you in advance for your help.

 
Upvote 0
dont thank me just yet, i dont have all the answers. i just do the best i can with what i know

i'm not sure why all values in C are changing to 02/01/1900 after running the code. the code shouldnt affect C as far as i can tell

what do the in values C look like before running the code?
 
Upvote 0
C values are just going to look like a date (ei. 31/07/2018...etc) from the formula I have provided above.

Formula Today() will give the date format and plus ETA (number of days) will result in a final date of delivery which is also in date format.
 
Upvote 0
i just dont know what went wrong
i'm sorry my suggestion didnt work out for you. hopefully someone else can give a better solution
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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