在消息框中输入一个数字,然后替换宏中的数字

时间:2014-04-04 14:58:45

标签: excel-vba vba excel

我有以下宏。当我运行宏时,我想要一个消息框来询问文件号。该文件号将替换宏中的000,宏将运行。

Application.ScreenUpdating = False

Range("C4:D4").Select
ActiveCell.FormulaR1C1 = "000"

Sheets("Sale ()").Select
Sheets("Sale ()").Name = "Sale (000)"

ActiveWorkbook.Save

Sheets("Sale (000)").Copy Before:=Workbooks("SALES INDEX.xls").Sheets(2)

Windows("SALES INDEX.xls").Activate
Sheets("Index").Select
Range("B3").Select
Selection.EntireRow.Insert
Range("A3").Select
ActiveCell.FormulaR1C1 = "000"
Range("A3").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
    "'Sale (000)'!C9"
Selection.Font.Underline = xlUnderlineStyleNone
Range("B4:F4").Select
Selection.Copy
Range("B3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "='Sale (000)'!R9C3"
Range("B3:F3").Select
Range("C3").Activate
ActiveCell.FormulaR1C1 = "='Sale (000)'!R3C36"
Range("B3:F3").Select
Range("D3").Activate
ActiveCell.FormulaR1C1 = "='Sale (000)'!R3C44"
Range("B3:F3").Select
Range("E3").Activate
ActiveCell.FormulaR1C1 = "='Sale (000)'!R5C36"

Application.ScreenUpdating = True

Sheets("Sale (000)").Select

1 个答案:

答案 0 :(得分:0)

将其插入顶部:

Dim st As String
st = Application.InputBox(Prompt:="enter file number", Type:=2)

然后小心地替换 000

例如:

ActiveCell.FormulaR1C1 = st

即使 st 是一个字符串,您也可以输入000之类的值并保留所有字符。

修改#1

另一个例子

取代:

"='Sale (000)'!R9C3"

"='Sale (" & st & ")'!R9C3"