我正在尝试用单个值连接一个范围。
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
为什么这不会将变量"组合"插入单元格?
更多解释(摘自评论)
基本上,我想获取 C 列的每个单元格中的值,并在所有单元格的末尾添加 00000。 因此,如果 C1 是 50,我希望最终结果复制到 50 并将 C1 替换为 5000000,如果 C2 是 575,则将其替换为 57500000,所有这些都在 C 中的数据范围内。
如果不可能,我宁愿将其粘贴在同一列中的值上。然后对于您给出的示例,我想要 D1= AAA00000、D2=BBB00000、D3 =CCC00000等
这是你正在尝试的吗?我给了你两条路。
方式 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