Option Explicit
#If VBA7 Then 'For 64 Bit Systems
'This is for pausing execution for x milliseconds (virtual key event listener).
'The call is (without quotes): "Sleep x".
'https://stackoverflow.com/questions/24274840/vba-sendkeys-c-seems-to-be-copying-to-a-different-clipboard
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else 'For 32 Bit Systems
'This is for pausing execution for x milliseconds (virtual key event listener).
'The call is (without quotes): "Sleep x".
'https://stackoverflow.com/questions/24274840/vba-sendkeys-c-seems-to-be-copying-to-a-different-clipboard
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub UnHide_Columns_In_Increments_Of_n_Pausing_In_Between() '***
Call Hide_Unhide_Columns_In_Increments_Of_n_Pausing_In_Between(ActiveSheet.Name, "C", "DF", 15, 0.5, "UnHide")
End Sub
Sub Hide_Columns_In_Increments_Of_n_Pausing_In_Between()'***
Call Hide_Unhide_Columns_In_Increments_Of_n_Pausing_In_Between(ActiveSheet.Name, "C", "DF", 15, 0.5, "Hide")
End Sub
Sub Hide_Unhide_Columns_In_Increments_Of_n_Pausing_In_Between( _
sheetName As String, _
firstColumnLetterToHideUnhide As String, _
lastColumnLetterToHideUnhide As String, _
numberOfColumnsToHideOrUnhideAtATime As Variant, _
numberOfSecondsToPauseInBetween As Long, _
hideOrUnhide As String _
)
'Application.ScreenUpdating = False '(Uncomment this once you see how this works.)
Application.EnableEvents = False
'Convert the column letters to numbers.
Dim firstColumnNumberToHideUnhide As Integer
firstColumnNumberToHideUnhide = Range(firstColumnLetterToHideUnhide & "1").Column
Dim lastColumnNumberToHideUnhide As Integer
lastColumnNumberToHideUnhide = Range(lastColumnLetterToHideUnhide & "1").Column
Dim totalNumberOfColumnsToHideUnhide As Integer
totalNumberOfColumnsToHideUnhide = lastColumnNumberToHideUnhide - firstColumnNumberToHideUnhide + 1
Dim increment As Integer
increment = numberOfColumnsToHideOrUnhideAtATime
Dim numberOfEqualIterations As Integer
numberOfEqualIterations = Floor(totalNumberOfColumnsToHideUnhide / increment)
Dim numberOfColumnsToHideUnhide_InTheLastIteration As Integer
numberOfColumnsToHideUnhide_InTheLastIteration = Modulous(totalNumberOfColumnsToHideUnhide, numberOfColumnsToHideOrUnhideAtATime)
Dim i As Integer
i = firstColumnNumberToHideUnhide
Dim currentIteration As Integer
currentIteration = 1
Do While currentIteration <= numberOfEqualIterations
With Sheets(sheetName)
If UCase(hideOrUnhide) = "HIDE" Then
.Range(.Cells(1, i), .Cells(1, i + numberOfColumnsToHideOrUnhideAtATime - 1)).EntireColumn.Hidden = True
'MsgBox .Range(.Cells(1, i), .Cells(1, i + numberOfColumnsToHideOrUnhideAtATime - 1)).Address
Else
.Range(.Cells(1, i), .Cells(1, i + numberOfColumnsToHideOrUnhideAtATime - 1)).EntireColumn.Hidden = False
End If
End With
Sleep numberOfSecondsToPauseInBetween * 1000
i = i + increment
currentIteration = currentIteration + 1
Loop
If numberOfColumnsToHideUnhide_InTheLastIteration > 0 Then
With Sheets(sheetName)
If UCase(hideOrUnhide) = "HIDE" Then
.Range(.Cells(1, i), .Cells(1, i + numberOfColumnsToHideUnhide_InTheLastIteration - 1)).EntireColumn.Hidden = True
'MsgBox .Range(.Cells(1, i), .Cells(1, i + numberOfColumnsToHideOrUnhideAtATime - 1)).Address
Else
.Range(.Cells(1, i), .Cells(1, i + numberOfColumnsToHideUnhide_InTheLastIteration - 1)).EntireColumn.Hidden = False
End If
End With
End If
'Application.ScreenUpdating = True '(Uncomment this once you see how this works.)
Application.EnableEvents = True
End Sub
Sub Test__Modulous()
MsgBox Modulous(5, 2)
End Sub
Function Modulous(a As Variant, B As Variant)
Modulous = a - B * Floor(a / B)
End Function
Sub Test__Floor()
MsgBox Floor(3.21)
MsgBox Floor(-3.21)
End Sub
Function Floor(number As Variant)
'Code from here: https://www.mrexcel.com/board/threads/floor-function-in-vba-code.218947/#post-1069232
Floor = Int(number) - 1 * (Int(number) > number)
End Function