简体   繁体   English

Excel宏-如果单元格具有特定值,则使接下来的2个单元格为空白

[英]Excel Macro - making next 2 cells blank if cell has a certain value

I'm trying to adapt a macro in an excel sheet so that if column AC = "FT" then AD and AE should be cleared. 我正在尝试在Excel工作表中调整宏,以便如果AC =“ FT”列,则应清除AD和AE。

I have tried searching for an answer but unable to find anything that works. 我尝试寻找答案,但找不到任何有效的方法。

Thanks 谢谢

If I understand your question correctly, then try the following code in the worksheet code module where you put your data. 如果我正确理解了您的问题,请在放置数据的工作表代码模块中尝试以下代码。

Sub Test()
Dim i As Long, LastRow As Long

LastRow = Cells(Rows.Count, "AC").End(xlUp).Row

For i = 1 To LastRow   'Set the value of i as a starting point depends on your first data is located
    If Cells(i, "AC").Value = "FT" Then
        Range(Cells(i, "AD"), Cells(i, "AE")).Clear     'Alternatively .Value = "" or .ClearContents
    End If
Next i

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 清除宏可清除特定列中空白单元格上特定范围的单元格 - Clear Macro to clear specific range of cells on Blank cell in certain column excel vba - 根据某个单元格是否具有某个值复制某些单元格(而不是整行) - excel vba - copy certain cells (as opposed to whole row) based on whether a certain cell has a certain value 无法为Excel VBA编写宏以将特定的单元格值复制到下一个空白行 - Unable to write a Macro for Excel VBA to copy a specific cell value to the next blank rows 在excel中制作宏以突出显示比控制单元格大的单元格 - Making a macro in excel to highlight cells that are bigger than a control cell VBA Excel-自动运行宏以在上面的单元格输入值后插入新的空白行 - VBA Excel - Auto run macro to insert new blank row after cell above has value entered Excel宏-如果cell.value具有“此文本”,则 - Excel Macro - If cell.value has 'this text' Then excel宏,用于调用复制在下一张工作表上的下一个单元格值 - excel macro for to call next cell value copied on the next sheet 宏Excel查找不包含值或空白的单元格值 - macro excel find a cell value that doesn't contain value or blank 在Excel中,如果相邻列具有特定值,如何计算列中的空白单元格? - In Excel, how do you count a blank cell in a column if an adjacent column has a certain value? Excel宏突出显示与当前单元格中的值匹配的所有单元格 - Excel macro to highlight all cells that match value in current cell
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM