[英]Excel - Copy selected cell and paste to the end of a column in another worksheet
[英]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
例如,在 B 列中,如果單元格值不是數字,則將該值復制到 C 列
如何制作該代碼?
請查詢!
這樣做的公式是: =IF(ISNUMBER(CELL), " ", CELL)
對於您的情況,將此代碼段放在 C2 中並將其復制下來: =IF(ISNUMBER(B2), " ", B2)
首先你需要找到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
結束子
你可以試試:
公式:
=IF(AND($B1<>"",ISNUMBER($B1)=FALSE),$B1,"")
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.