List cells based on text macro

garyi

New Member
Joined
Oct 3, 2013
Messages
22
Hello folks

I have created a spreadsheet which has a row listing all dates in 2019.
Under this we will add rows for various contracts so we can colour the cells based on various dates needed for the contract over the year. There are 7 date specific things that are in a drop down format so it will always be specific text.
This goes across the whole year so is a bit unwieldy to review.

So what I want to do is have macro that will look through that range of cells for this specific text, for instance 'start date' and list that information on another tab, with the date from the date row above alongside it.

I hope that makes sense. It does not actually have to be a macro but if anyone can give me a nudge in the right direction that would be appreciated.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Good - it is finding the dates
Will update later today for you
 
Upvote 0
I have no idea what I have done with my date line, I could just redo the whole sheet from scratch there is not a lot too it at the moment.
 
Upvote 0
Ok - try this

This is what I get:
Example Contract1Example Contract2Example Contract3Example Contract4Example Contract5
1st App01/01/201902/01/201903/01/201904/01/201905/01/2019
pre qual02/01/201903/01/201904/01/201905/01/201906/01/2019
site visit03/01/201904/01/201905/01/201906/01/201907/01/2019
tender sub04/01/201905/01/201906/01/201907/01/201908/01/2019
shortlist05/01/201906/01/201907/01/201908/01/201909/01/2019
presentation06/01/201907/01/201908/01/201909/01/201910/01/2019
decision07/01/201908/01/201909/01/201910/01/201911/01/2019
award08/01/201909/01/201910/01/201911/01/201912/01/2019
start date09/01/201913/01/201911/01/201914/01/201915/01/2019

<tbody>
</tbody>



If you have any problems look in Immediate Widow (generated by Debug.Print Contract, Milestone, c, r )
This is what I get for the first contract (Contract Name, milestone value from cell, contract column in new sheet, milestone row in new sheet):
Example Contract1 1st App 2 2
Example Contract1 pre qual 2 3
Example Contract1 site visit 2 4
Example Contract1 tender sub 2 5
Example Contract1 shortlist 2 6
Example Contract1 presentation 2 7
Example Contract1 decision 2 8
Example Contract1 award 2 9
Example Contract1 start date 2 10


Code:
Sub CreateTable5()
Const MySheet = "Data"
Dim Main As Worksheet, NewSheet As Worksheet
Dim Contracts As Range, DateRng As Range, Contract As Range, cel As Range
Dim Milestones As Variant, Milestone As Variant, c As Long, r As Long
Set Main = Sheets(MySheet)
Set NewSheet = Sheets.Add(after:=Main)
Set Contracts = Main.Range("B10", Main.Range("B" & Rows.Count).End(xlUp))
Set DateRng = Main.Range("F8", Main.Cells(8, Columns.Count).End(xlToLeft))
'add column headers
    Contracts.Copy
    NewSheet.Range("B1").PasteSpecial Paste:=xlPasteAll, Transpose:=True
'add row headers
    Milestones = Split(Main.Range("F10").Validation.Formula1, ",")
    NewSheet.Range("A2").Resize(UBound(Milestones) + 1).Value = WorksheetFunction.Transpose(Milestones)
'add values
    For Each Contract In Contracts
        For Each cel In Main.Cells(Contract.Row, "F").Resize(, DateRng.Columns.Count)
            Milestone = cel.Value
            If Milestone <> "" Then
                On Error Resume Next
                c = NewSheet.Range("1:1").Find(Contract).Column
                r = NewSheet.Range("A:A").Find(Milestone).Row
                [COLOR=#ff0000]Debug.Print Contract, Milestone, c, r[/COLOR]
                NewSheet.Cells(r, c) = DateValue(Main.Cells(8, cel.Column))
            End If
        Next cel
    Next Contract
'formatting
    With NewSheet.Range("A1").CurrentRegion
        .Rows(1).Font.Bold = True
        .Rows(1).WrapText = True
        .Columns(1).Font.Bold = True
        .ColumnWidth = 15
        .HorizontalAlignment = xlCenter
        .Borders.LineStyle = xlContinuous
    End With
End Sub
 
Last edited:
Upvote 0
Excellent, thanks for feedback :)
You can delete Debug.Print line
 
Last edited:
Upvote 0
Good morning Yongle, or anyone else that can help!

I need to make some adjustments.

I seem to recall there is a way to put the macro so that when you select the worksheet it automatically does it?

Or at least I would like to have just one work sheet where this data populates at the moment it creates a new sheet everytime, or perhaps it could delete that sheet first?

I would also like to use the alternate layout, or at least my colleagues would!

Any help you can offer would be appreciated.
 
Upvote 0

Forum statistics

Threads
1,215,170
Messages
6,123,416
Members
449,099
Latest member
COOT

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