Menu

Selasa, 27 Februari 2018

Buat name sheet di Range pakai vb Excel

nama sheet di taruh di B1
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
[B1]=[B1]&","& sh.Name
Next sh


Nama Sheet di taruh di B1 ke bawah

For i = 1 To Sheets.Count
Cells(i, 2) = Sheets(i).Name
Next i

Nama Sheet di buat data validasi Vba excel

Private Sub CommandButton1_Click()
Dim wsArray As Variant
    Dim sWsList As String
    Dim x As Integer
    wsArray = AllWorkSheets()
    sWsList = Join(wsArray, ",")
    With Sheets(1).Range("A1").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=sWsList
    End With
End Sub
Public Function AllWorkSheets() As Variant
    Dim wsArray() As Variant
    Dim x As Integer
        ReDim wsArray(Sheets.Count - 1)
        For x = 0 To Sheets.Count - 1
        wsArray(x) = Sheets(x + 1).Name
    Next x
        AllWorkSheets = wsArray
    End Function

Nama Sheet di buat ComboBox Vba excel

Private Sub Worksheet_Activate()
ComboBox1.Clear
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
Me.ComboBox1.AddItem sh.Name
Next sh
End Sub

Vb Mengurutkan Name sheet di Excel

Dim a, b, c, p As Integer
On Error GoTo Gagal

c = Sheets.Count
For a = 2 To c 
  p = a
  For b = a - 1 To 1 Step -1
    If Sheets(a).Name < Sheets(b).Name Then
      p = b
    End If   
  Next
  If p <> a Then
    Sheets(a).Move Before:=Sheets(p)
  End If
Next

Sheets(1).Select

Gagal: