VBA Replace text in column, if column header is a specific text

anarchyflag

New Member
Joined
Nov 2, 2018
Messages
15
I have a report which plots venue availability against dates (see layout below)

1585310943779.png


The information comes through as Fullday / Morning / Afternoon, and if used will say Booked.

None of the venues are used on Sundays, except to set up. However, this data still comes through as a full day availability, which messes with calculations used for reporting later down the line (can look like the venues have offered more availability than they actually have).

I have the following two pieces of code in place already:

VBA Code:
Sub Find_replace()
    Range("A:AAA").Select
    Selection.Replace What:="Fullday", Replacement:="***Full", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
End Sub

This searches for cells with “Fullday” and replaces it with “***Full” across the entire worksheet.

VBA Code:
Sub Sunday_widths()
Dim Range1 As Range
Dim Cell1 As Range
Set Range1 = Range("O1:AAA1")
For Each Cell1 In Range1
    Select Case True
        Case Celll Like "*Sun*"
            Cell1.ColumnWidth = 7.5
    End Select
Next Cell1
End Sub

This searches for any column with “Sun” in Row 1, and sets the width of the column based on that.

Is there any way to combine these two, so that the macro searches for any column with Sun in the top row, selects that column and replaces any text “***Full” with “Set up”?

Thanks very much in advance!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Actually, I've just solved it:

Sub Sunday_avails()

VBA Code:
Dim Range1 As Range
Dim Cell1 As Range
Set Range1 = Range("O1:AAA1")
    For Each Cell1 In Range1
        Select Case True
            Case Cell1 Like "*Sun*"
                Cell1.EntireColumn.Replace What:="***Full", Replacement:="*Set up", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        End Select
    Next Cell1
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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