How to improve the speed of VBA macro code?

Just reiterating what has already been said: Option Explicit Sub Macro1() ‘turn off as much background processes as possible With Excel.Application .ScreenUpdating = False .Calculation = Excel.xlCalculationManual .EnableEvents = False End With Dim historyWks As Excel.Worksheet Dim inputWks As Excel.Worksheet Dim nextRow As Long Dim oCol As Long Dim myCopy As Excel.Range Dim myTest As … Read more

Is there a way for DIR(path) in VBA to handle strings longer than 260?

Shortly put (to answer the answer as titled): No. VBA’s Dir function simply does not work with paths beyond 260 characters. Long version: http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maximum_path_length (then Ctrl+F and search for “260”) Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which … Read more

Loop through cells and add to a range

Something like this using Union to glue together your range Please note that For each loops are quicker than a For i = 1 to x approach You may well be able to use SpecialCells to determine your new range instantly (e.g. any blanks, any errors, any formulae, etc) Sub Test() Dim rng1 As Range … Read more

How do I get a list of unique values from a range in Excel VBA?

I would use a simple VBA-Collection and add items with key. The key would be the item itself and because there can’t be duplicit keys the collection will contain unique values. Note: Because adding duplicit key to collection raises error wrap the call to collection-add into a on-error-resume-next. The function GetUniqueValues has source-range-values as parameter … Read more

Hiding active workbook programmatically in Excel

Hiding the active workbook is possible with ActiveWorkbook.Windows(1).Visible = False You may need to replace ActiveWorkbook with an appropriate reference if the workbook in question is not the active one and/or add a loop like For i = 1 To ActiveWorkbook.Windows.Count if the workbook has multiple windows.