Query my excel worksheet with VBA

You can programmtically create an AutoFilter, then select the matching values: Dim ws As Worksheet: Set ws = ActiveSheet With ws .AutoFilterMode = False .Range(“1:1”).AutoFilter .Range(“1:1″).AutoFilter field:=2, Criteria1:=”=Saturday”, Operator:=xlAnd With .AutoFilter.Range On Error Resume Next ‘ if none selected .Offset(1).Resize(.Rows.Count – 1).Columns(2).SpecialCells(xlCellTypeVisible).Select On Error GoTo 0 End With .AutoFilterMode = False End With

What does the To and Step mean in VBA?

from high number To 1 adding (-1) each iteration Note: It’s adding because + AND – in mathematical logic evaluate to a – If rows = 10 then for i = 10 to 1 step -2 would mean loop back from 10 to 1 subtracting 2 from the i in each loop cycle. adding a … Read more

Excel VBA Run-time error 1004 when inserting or value formula into cell

Inserting a formula with VBA requires that you use EN-US standards like, Range(“B64”).Formula = “=INDEX(AK7:AK123, G74, 1)” … or use the regional formula attribute like, Range(“B64”).FormulaLocal = “=INDEX(AK7:AK123; G74; 1)” You may have to also change INDEX to the regional equivalent. The latter is necessary when you have a system with regional settings that do … Read more

Read and write from/to registry in VBA

I think the problem here was that the macro did not have permission to write to the registry. More information in this page. I could read the key’s value using the WScript object just fine: Debug.Print CreateObject(“WScript.Shell”).RegRead(“HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR\Start”) To write (it should work if you have permissions): CreateObject(“WScript.Shell”).RegWrite “HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR\Start”, 4, “REG_DWORD” How I got it to … Read more