1

我希望我的公式在我的列左侧产生一个句点和变量名称,它指的是工作表名称。例如,如果左边的列是 10,工作表名称是 12。我的值是 10.12

我尝试了以下方法,但我无法让 Name 显示为变量而不是“Name”

Dim ws As Worksheet
Dim Name As Integer

For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    Name = ws.Name

    Range("C2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]&""."" & Name "
Next ws

谢谢你的帮助。

4

1 回答 1

2

这似乎让你更接近:

Dim Name As String
Dim Output As String

Name = ActiveSheet.Name


Output = ActiveCell.Offset(0, -1).Value & "." & Name


ActiveCell.FormulaR1C1 = Output

这是您的代码,没有所有选择:

Sub foo()
Dim ws As Worksheet
Dim Name As String
Dim Output As String

For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    Name = ws.Name
    Output = ws.Range("C2").Offset(0, -1).Value & "." & Name
    ws.Range("C2").FormulaR1C1 = Output
Next ws
End Sub
于 2013-04-08T17:59:11.830 回答