复制单元格的范围,只选择具有数据的单元格,而不是公式 [英] Copy a range of cells and only select cells with data and just the value not the formulas
问题描述
我正在寻找一个宏来复制一系列单元格,但只能复制包含值的单元格,而不是公式的值。
我的问题几乎是这样的:
我发现这个宏观brilljant :)但它只是错过了我需要的:($ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $这将减慢你的代码。
'循环列和行
对于iCol = 1到3'许多列你有
对于iRow = 1对于iMaxRow
与工作表(Sheet1)。单元格(iRow,iCol)
'检查该单元格不为空
如果.Value =然后
'此单元格中没有任何
'不做任何
否则
'将单元格复制到目标
.Copy目标:=工作表(Sheet2)。cells(iRow,iCol)
如果
结束
下一步iRow
下一步iCol
我希望你们中的一些天才可以帮助我。
最好的问候。
Ringo
简单 - 只需编辑Else语句...
'循环通过列和行
对于iCol = 1至3',或许多列您有
对于iRow = 1 To iMaxRow
使用工作表(Sheet1)。单元格(iRow,iCol)
'检查单元格是否不为空。
如果.Value =然后
'此单元格中没有任何内容。
'什么都不做
Else
'将单元格复制到目标
工作表(Sheet2)。cells(iRow,iCol).value = .value
End If
End With
下一步iRow
下一步iCol
希望这是你意味着....
I'm looking for a macro to copy a range of cells, but to only copy the cells that contain a value and just the value not the formulas.
My problem is almost like this one:
Copy a range of cells and only select cells with data
I found this macro brilljant :) but it's just missing what I need :(
iMaxRow = 5000 ' or whatever the max is. 'Don't make too large because this will slow down your code.
' Loop through columns and rows
For iCol = 1 To 3 ' or however many columns you have
For iRow = 1 To iMaxRow
With Worksheets("Sheet1").Cells(iRow,iCol)
' Check that cell is not empty.
If .Value = "" Then
'Nothing in this cell.
'Do nothing.
Else
' Copy the cell to the destination
.Copy Destination:=Worksheets("Sheet2").cells(iRow,iCol)
End If
End With
Next iRow
Next iCol
I hope some of you geniuses can help me. Best regards. Ringo
Easy - Just edit the Else statement a bit...
' Loop through columns and rows
For iCol = 1 To 3 ' or however many columns you have
For iRow = 1 To iMaxRow
With Worksheets("Sheet1").Cells(iRow,iCol)
' Check that cell is not empty.
If .Value = "" Then
'Nothing in this cell.
'Do nothing.
Else
' Copy the cell to the destination
Worksheets("Sheet2").cells(iRow,iCol).value = .value
End If
End With
Next iRow
Next iCol
Hope this is what you meant....
这篇关于复制单元格的范围,只选择具有数据的单元格,而不是公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!