excel 有關sheet的問題 感謝各位高高手解答

在某Sheet裡面A1~A5有各個名稱 想要利用VBA去選擇以A1至A5為sheet名稱 該如何寫才好呢?

因為我寫了以下的式子但是卻顯示錯誤

sheet(cell(i,"A")).select 其中i是變數

3 Answers

Rating
  • 1 decade ago
    Best Answer

    Sub mysheetrename()

    Dim mysheetname As Variant

    Dim myMsg As String, myTitle As String

    myMsg = "請輸入名稱"

    myTitle = "Data base"

    mysheetname = Application.InputBox(prompt:=myMsg, Title:=myTitle, Type:=2)

    If mysheetname = ture Then

    MsgBox "請輸入名稱"

    ElseIf mysheetname <> False Then

    ActiveSheet.Name = mysheetname

    End If

    End Sub

    當出現"請輸入名稱"對話方框時.將滑鼠點選A1~A5其中之一.按確定既可.

  • Anonymous
    1 decade ago

    先釐清你的問題唷~

    1) 在VBA中要指定某個儲存格有兩種方式:

    by cells, cells(raw,column), 例如要指定A2, ==> cells(2,1).select

    be range, Range("A2").select

    2) In your case:

    Set mysheet = Worksheets("main") '先設定你的主工作表名稱

    For i = 1 To 5

    sheetname = mysheet.Cells(i, 1) '指定你要的工作表名稱

    Sheets(sheetname).Activate

    Next i

    : )試試看吧~~

  • 幽靈
    Lv 5
    1 decade ago

    Application.Goto Reference:="名稱"

    還是你說的是下面這個 @@;

    Range("A1").Select

Still have questions? Get your answers by asking now.