[英]Excel VBA, If cell is not numeric and empty in a column, selected cell copy and paste to another column
A B C
a rm rm
b
c
d 4000
e 5000
f r1 r1
g c1 c1
h 103
i 1.8
For example, in B Column, if cell value are not number, copy the value to C Column例如,在 B 列中,如果单元格值不是数字,则将该值复制到 C 列
how to make that code?如何制作该代码?
please, inquiry for that!请查询!
The formula to do it would be: =IF(ISNUMBER(CELL), " ", CELL)这样做的公式是: =IF(ISNUMBER(CELL), " ", CELL)
For your case put this snippet right in C2 and copy it down: =IF(ISNUMBER(B2), " ", B2)对于您的情况,将此代码段放在 C2 中并将其复制下来: =IF(ISNUMBER(B2), " ", B2)
At first you need to find the last non blank row number of column A. Then run a loop and check if the value of column A is numeric or not.首先你需要找到A列的最后一个非空行号。然后运行一个循环并检查A列的值是否为数字。
Public Sub M()
Dim sh As Worksheet
Set sh = Worksheets("Worksheet name here")
Dim lastrow As Long, i As Long
lastrow = sh.Cells(1048576, 2).End(xlUp).Row
For i = 1 To lastrow
If IsNumeric(.Cells(i, 2).Value) = False Then
.Cells(i, 3).Value = .Cells(i, 2).Value
End If
Next i
End Sub结束子
You could try:你可以试试:
Formula:公式:
=IF(AND($B1<>"",ISNUMBER($B1)=FALSE),$B1,"")
VBA: VBA:
Sub test()
Dim LastRow As Long, i As Long
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
If .Range("B" & i).Value <> "" And Not IsNumeric(.Range("B" & i).Value) Then
.Range("C" & i).Value = .Range("B" & i).Value
End If
Next i
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.