简体   繁体   中英

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:

. ABCD

1 tttt

2 tttt

3 ..... t

4 tttt

5 tttt

6 ..... t

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM