我尝试使用单个值连接范围。
Sub Macro1()
Dim rngOne As Range, strngOne as String, combos As Range
'finds the last row and sets it as the ending range
Dim LastRowColC As Integer
LastRowColC = Range("C65536").End(xlUp).Row
Set rngOne = Worksheets(1).Range("C3" & LastRowColC)
strngOne = "00000"
combos = rngOne & strngOne
Range("D3").Select
Insert combos
End Sub
为什么不插入变量" combos"进入牢房?
更多解释(复制自评论)
基本上我想获取C列的每个单元格中的值,并将00000添加到所有单元格的末尾。因此,如果C1为50,我希望最终结果复制到50,并将C1替换为5000000,如果C2为575,则将其替换为57500000,在C中的所有数据范围内。
如果不可能,我希望将其粘贴到同一列中的值。那么对于你给出的例子我想要D1 = AAA00000,D2 = BBB00000,D3 = CCC00000等
答案 0 :(得分:3)
这是你在尝试什么?我给了你两种方法。
方式1
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long
Dim rng As Range
'~~> Change this to the relevant worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
'~~> Get last row in Col C
lRow = .Range("C" & .Rows.Count).End(xlUp).Row
'~~> Construct your range
Set rng = .Range("C3:C" & lRow)
'~~> Multiply all the cells in the range with 100000
'~~> so that 55 become 5500000, 123 becomes 12300000 and so on
rng.Value = Evaluate(rng.Address & "*100000")
End With
End Sub
第2天
在单元格D1中键入100000
,然后运行此宏
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long
Dim rng As Range
'~~> Change this to the relevant worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
'~~> Get last row in Col C
lRow = .Range("C" & .Rows.Count).End(xlUp).Row
'~~> Construct your range
Set rng = .Range("C3:C" & lRow)
'~~> This cell has 100000
.Range("D1").Copy
'~~> Paste Special Value/Multiply
rng.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlMultiply, _
SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
End With
End Sub