如果列标题是特定文本,则替换列中的文本

问题描述 投票:0回答:1

我有一份报告,根据日期绘制了场地的可用性(请参见下面的布局)

enter image description here

信息通过全天/上午/下午显示,如果使用,则表示已预订。

[除了场地之外,没有一个场地在星期日使用。但是,这些数据仍然是一整天的可用性,这与后来用于报告的计算混乱(看起来这些场所提供的可用性超出了实际的可用性)。

我已经有以下两段代码:

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

这将在整个工作表中搜索带有“全天”的单元格,并将其替换为“ ***全”。

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

这将搜索第1行中任何带有“ Sun”的列,并根据该列设置宽度。

是否有任何方法可以将这两者结合在一起,以便宏在第一行中搜索带有Sun的任何列,选择该列并将任何文本” *** Full”替换为“ Setup”?

非常感谢!

编辑:

Sub Sunday_avails()

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.EntireColumn.Replace What:="***Full", Replacement:="*Set up", LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False
        End Select
    Next Cell1
End Sub
excel vba
1个回答
0
投票

只需在Replace上调用.EntireColumn

Cell1.EntireColumn.Replace What:="***Full", Replacement:="*Set up"...
© www.soinside.com 2019 - 2024. All rights reserved.