简体   繁体   English

Excel VBA-将单元格值(如果为空)复制到同一行中的另一个单元格

[英]Excel VBA - Copy Cell Value, if empty, to another Cell in the same row

I am a complete new starter to VBAs and would require your help, my data looks like this: 我是VBA的全新入门者,需要您的帮助,我的数据如下所示:

. ABCD A B C D

1 tttt 1 tttt

2 tttt 2 tttt

3 ..... t 3 ..... t

4 tttt 4 tttt

5 tttt 5 tttt

6 ..... t 6 ..... t

7 tttt 7 tttt

The Macro should check, whether there is some information in Column A:A and if it is empty it should delete the value in the same row in column D. 宏应检查A:A列中是否有某些信息,如果为空,则应删除D列同一行中的值。

I hope that you can help me. 我希望你能帮助我。

Thanks in advance. 提前致谢。

Kind regards 亲切的问候

As per my understanding on your question, try the below code. 根据我对您问题的理解,请尝试以下代码。

Dim i As Integer
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
If Range("A" & i) = "" Then
Range("D" & i).ClearContents
End If
Next i

您实际上不需要循环和一个内衬:

Range("A1", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeBlanks).Offset(, 3).ClearContents

暂无
暂无

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

相关问题 EXCEL VBA-遍历一行中的单元格,如果不为空,则将单元格值复制到另一行,直到下一行不为空 - EXCEL VBA - Loop through cells in a row, if not empty, copy cell value into another row until next row not empty Excel函数复制如果当前单元格为空且同一行中的另一个单元格为空,则该单元格值高于IF。 否则,什么都不做 - Excel function to copy cell value above IF current cell empty and another cell in same row is anything but empty. Otherwise, do nothing VBA,Excel宏:将单元格值复制到另一个工作表,偏移,重复直到找到空单元格 - VBA, Excel macros: copy cell value to another sheet, offset, repeat until finding an empty cell 如果> 0,则Excel VBA将单元格值复制到左侧的单元格 - Excel VBA to copy cell value if > 0 to cell to the left 如何在Excel VBA中将单元格从一行复制到另一行 - How to copy cell from one row to another in excel vba Excel VBA在另一张工作表中查找一行,然后更改同一行中的单元格 - Excel VBA Find a row in another sheet, then change a cell in the same row Excel:如果某个单元格不为空,则将一行复制到另一个工作表 - Excel: Copy a row to another worksheet if a certain cell is not empty 使用vba将单元格的值复制到另一个单元格 - Use vba to copy value of cell to another cell Excel Vba - 如果单元格中的值大于,则复制行 - Excel Vba - Copy row if value in cell is greater than Excel VBA-根据单元格值复制和插入行 - Excel VBA- copy and insert row based on cell value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM