使用不带复制的左键&粘贴 [英] Using Left without Copy & Paste
问题描述
我有一些数据想要基本上减少到前12个数字,无论它输出多少.我当前的操作方式是从C列中获取数字,在GI列中使用公式= Left(C3,12)然后向下拖动使其与C中的范围匹配.然后运行一个看起来像这个:
I have some data that I want to be basically cut down to the first 12 numbers no matter how many it goes out. The way I'm currently doing it is taking the numbers from the column C and in Column G I have a formula =Left(C3,12) I then drag down so it matches the range in C. Then I run a macro that looks like this:
Sub Macro6()
Range("G3:G7").Select
Selection.Copy
Range("C3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
这可行,但我必须不断更新范围,而且有点笨拙.有谁知道完成同一件事的更好方法?(基本上使C中的值仅成为前12位数字)
This works but I have to constantly update the range, and it's kind of clunky. Does anyone know a better way to accomplish the same thing? (basically making the values in C become the first 12 digits only)
推荐答案
如果我对您的理解是正确的,那么您希望将C列中单元格的内容替换为该单元格中前12位数字.
If I understand you correctly, your wanting to replace the contents of a cell in column C with the first 12 digits of whatever is in that same cell.
从如下所示的数据开始:
Starting with data that looks like this:
运行此:
Sub keep12()
Dim wks As Worksheet
Set wks = Worksheets("Sheet1")
Dim rng As Range
Set rng = wks.Range("C3:C" & wks.Range("C" & wks.Cells.Rows.Count).End(xlUp).Row)
For Each cell In rng
cell.Value = Left(cell.Text, 12)
Next cell
End Sub
结果:
这篇关于使用不带复制的左键&粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!