使用列标题列字母代码来设置macros的范围
我有不断移动的列,我试图重写一些macros使用标题名称。 在将代码应用于Sub时遇到一些麻烦。
Trying to replace this: Columns("EO:EO").Select
与Columns("aCell:aCell").Select
尝试了其他各种方式,但我什么也没有工作。
谢谢
Function LCol(ColumnNumber As Long) As String Dim ColNum As Integer Dim ColLetters As String ColNum = ColumnNumber ColLetters = "" Do ColLetters = Chr(((ColNum - 1) Mod 26) + 65) & ColLetters ColNum = Int((ColNum - ((ColNum - 1) Mod 26)) / 26) Loop While ColNum > 0 LCol = ColLetters End Function
小组
Sub RenameOther() Dim strSearch As String Dim aCell As Range Dim colz As Range strSearch = "attribute_4" Set aCell = Sheet1.Rows(1).Find(What:=strSearch, LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If Not aCell Is Nothing Then 'Trying to replace this: Columns("EO:EO").Select Columns("aCell:aCell").Select Selection.Replace What:="Client/Customer/Other (optional)", Replacement:="Other", _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _ False, ReplaceFormat:=False Cells(2, aCell.Column).Select End If End Sub
或者,你可以试试这个:
aCell.EntireColumn.Select
'Trying to replace this: Columns("EO:EO").Select Columns(aCell.Column).Select
Sub Tester() ReplaceColumnContent "attribute_4", "Client/Customer/Other (optional)", "Other" End Sub Sub ReplaceColumnContent(colHeader As String, LookFor As String, ReplaceWith As String) Dim strSearch As String Dim aCell As Range Dim colz As Range Set aCell = Sheet1.Rows(1).Find(What:=colHeader, LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If Not aCell Is Nothing Then With Sheet1.Range(aCell.Offset(1, 0), Sheet1.Cells(Rows.Count, aCell.Column).End(xlUp)) .Replace What:=LookFor, Replacement:=ReplaceWith, _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False End With 'aCell.offset(1,0).select End If End Sub
- 在VBA中删除前后单元格中不需要的字符(excel)
- Apache POI&SXSSF:行数始终为0
- Application.EnableEvents = true每次返回false
- 我有3个Excelexpression式,我想用电子表格填充范围,我怎样才能确保单元格与行更改?
- 在使用LIKE运算符时,使用来自访问的OLEDB连接的Excel中的数据不会更新
- 使用Excel工作表公式查找ASCII字符的范围
- 使用click once on non dev pcs从GAC中缺lessMicrosoft.VisualStudio.OfficeTools.Controls.ManagedWrapper
- Excel条件格式 – 在其他单元格中匹配或部分匹配值
- 在Excel中转换为matrix格式