“Loop melalui sel” Kode Jawaban

Loop melalui sel

Sub ForEachItemInArray()
    Dim arrValue As Variant
    Dim Item As Variant
    arrValue = Array("Item 1", "Item 2", "Item 3")
    
    For Each Item In arrValue
        MsgBox Item
    Next Item
    
End Sub
Yellowed Yak

Loop melalui sel

Sub If_Loop()
Dim Cell as Range
 
  For Each Cell In Range("A2:A6")
    If Cell.Value > 0 Then
      Cell.Offset(0, 1).Value = "Positive"
    ElseIf Cell.Value < 0 Then
      Cell.Offset(0, 1).Value = "Negative"
    Else
      Cell.Offset(0, 1).Value = "Zero"
     End If
  Next Cell
 
End Sub
Yellowed Yak

Loop melalui sel

Sub ForEachCell()
    Dim Cell As Range
    
    For Each Cell In Sheets("Sheet1").Range("A1:A10")
        Cell.Offset(0, 1).value = Cell.value
    Next Cell
    
End Sub
Yellowed Yak

Loop melalui sel

Sub HideAllSheets()
    Dim ws As Worksheet
 
    For Each ws In Sheets
        ws.Visible = xlSheetHidden
    Next ws
    
End Sub
Yellowed Yak

Loop melalui sel

Sub ForEachWorkbooks()
    Dim wb As Workbook
    
    For Each wb In Workbooks
        wb.Close
    Next wb
    
End Sub
Yellowed Yak

Loop melalui sel

Sub ProtectAllSheets()
    Dim ws As Worksheet
 
    For Each ws In Sheets
        ws.Protect Password:="..."
    Next ws
    
End Sub
Yellowed Yak

Loop melalui sel

Sub ForEachCharts()
    Dim cht As ChartObject
    
    For Each cht In Sheets("Sheet1").ChartObjects
        cht.Delete
    Next cht
    
End Sub
Yellowed Yak

Loop melalui sel

Sub ForEachTables()
    Dim tbl As ListObject
    
    For Each tbl In Sheets("Sheet1").ListObjects
        tbl.Delete
    Next tbl
    
End Sub
Yellowed Yak

Loop melalui sel

Sub DeleteAllShapesOnAllWorksheets()
    Dim Sheet As Worksheet
    Dim Shp As Shape
    
 
    For Each ws In Sheets
        For Each Shp In ws.Shapes
            Shp.Delete
        Next Shp
    Next ws
    
End Sub
Yellowed Yak

Loop melalui sel

Sub ForEachNumberInNumbers()
    Dim arrNumber(1 To 3) As Integer
    Dim num As Variant
    
    arrNumber(1) = 10
    arrNumber(2) = 20
    arrNumber(3) = 30
    
    For Each num In arrNumber
        Msgbox Num
    Next num
    
End Sub
Yellowed Yak

Jawaban yang mirip dengan “Loop melalui sel”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya