Vishesh's blog

Vishesh's picture

Answer to Forum question

Refer attached Excel file for answer to forum question on
http://excelexperts.com/creating-2nd-list-dependent-1st-list

See data validation criteria conditions on Cell A2 and B2. Also see Named ranges created (dynamic named ranges can also be used here)

Vishesh's picture

Task Management Utility

Here is small Task Management Utility with facility to view Reports. Give it a try and give your feedback and suggestions.

Task Management

Vishesh's picture

UK Tax Calculator (Simple & Comprehensive)

Download the attached UK Tax Calculator Excel file having simple and comprehensive tax calculator.

Simple Tax Calculator:

Simple Tax Calc

Comprehensive Tax Calculator:

Comprehensive Tax Calc

Vishesh's picture

Leave System

This is a small Leave system utility. Download the attached zip file and extract excel and access file from it. This can be used in a multi user environment as well by keeping the access database at a commonly accessible location and distributing the excel file to all users. In the access database there is a table 'M_LeaveTypes' from where you can maintain the Leave Type and Max Carry over for each type of leave. In this system an user is identified by his Windows login id.

Vishesh's picture

Multiple Choice (Questionnaire/Survey) generator

Here is an utility to generate a simple multi choice questionnaire/survey (as you wish to use it). The survey response files can be collated using the collate responses button and selecting the created files

Multi Choice

Vishesh's picture

Small Shop Utility (for mid-sized shops)

This is a small utility to speed up the process of buying and selling between a Shopkeeper and a Customer. There are two sections (excel files) of it - Shopkeeper and Customer.

The Shopkeeper file as shown below remains with the shopkeeper where he can add/delete/modify items (Click Manage Items) and prices in the stock. 

The Update Customer copy button allows you to choose the other customer copy provided to be updated with the updated items and prices. This updated customer copy is then emailed/sent to the customer.

Vishesh's picture

Sorting on Custom Sort Order (VBA)

Following piece of code sort the data based on custom sort order. You can provide your own sort order in a separate table. For illustration, download the attached file.

Custom Sort

 


Sub TestCustomSort()

    Dim rngSortOrder    As Range

    Dim rngSortValues   As Range

    Dim arrSortOrder

 

Vishesh's picture

Sort on 'n' no. of Fields (VBA)

Copy-Paste the following code in a general module and run. Alternatively, download the attached file to see how it works. You can pass field names (Column headers) or Column Index as function parameters.


 

 

Sub TestIt()

    Call CustomSort(Sheet1.UsedRange, True, "F1", "F4")

     'or

    'Call CustomSort(Sheet1.UsedRange, True, 1, 4)

End Sub

 

Vishesh's picture

Filter records using arrays (VBA)

Put the following code in a general module and run. You can download the attachment as well to see how it works.


 

Sub TestIt()

    Dim rngTgt As Range

    Dim arr

 

'Target where you want to see filtered data

    Set rngTgt = Sheet1.Range("J2")

    rngTgt.CurrentRegion.Offset(1).ClearContents

    

'Calling function with parameters

Vishesh's picture

Cell Content Change History in Comments

Copy the following code in Thisworkbook module.

This will record any cell change in the cell comment. There is a constant at the beginning of the code module; you can set the number of records in comments (history) to be maintained. Specifying 0 means no record limit. This applies to the whole workbook.

Const gc_intMaxCmtHistory As Integer = 5 'Max Comments History allowed

                                         'Change it to 0 to allow n no.
Vishesh's picture

Simple Multiple Source Pivot

Follow these steps to create a pivot table from multiple sources (same of other file). See attached example file.

Steps :
1a In Excel 2003 open the PivotTable and PivotChart wizard by choosing Data -> PivotTable and PivotChart Report.
1b In Excel 2007, press Alt+DP, then type P to open the wizard as there is no equivalent menu option.
2 Choose Multiple Consolidation ranges
3 Open file B as well
4 Choose relevant page field option
5 Simply select and add the ranges (highlighted cells) from this and other file. You can choose to have as many files (A+B)
6 Select New Sheet & Finish

Vishesh's picture

Answer to Blog

This is the solution to blog on url
http://excelexperts.com/help

Please see attached xl file.

Vishesh's picture

Export to and Import from Tab delimited Text file

Following are two functions to Export to and Import from Tab delimited Text file.
Vishesh's picture

Text/Number Validation in Text Boxes

Copy the following code in a general module and call it from any of the textboxes' keypress event.
Vishesh's picture

Solution-Copy data range to new worksheet

Solution for problem posted on url

http://excelexperts.com/copy-range-data-new-worksheet-when-matching-data...

Please see attached sheet. Click on the button provided on the sheet.

Vishesh's picture

Customised Progress Bar

Download the attached Excel workbook to see how the customised progress bar works. To implement this in your project simply copy the form (frmProgress) and general module (modProgressBar). And then, you just need to call ShowProgress procedure like this

Call ShowProgress("Task 4", 10)  
where "Task 4" is the task name and 10 is percentage completion of the task.

Customised Progress Bar

Vishesh's picture

VBA code to handle Access Imports and Query

Paste the following code in a general module
Public g_objConnection As ADODB.Connection
Public Const gc_strDBPath As String = "C:\Test.mdb"
 
Function blnConnectDatabase(strPath As String, strDBPass As String) As Boolean
'    If blnFileExists(strPath) = False Then
'        GoTo ErrH
'        Exit Function
'    End If
    Set g_objConnection = New ADODB.Connection
    On Error GoTo ErrH
    g_objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
        strPath & ";Jet OLEDB:Database Password=" & strDBPass & ";"
    On Error GoTo 0
    blnConnectDatabas
Vishesh's picture

Solution to Forum Ques

Solution for Forum Ques on url:

http://excelexperts.com/vishesh-need-macro-help

Vishesh's picture

Rows to column solved

Solution for problem asked in url: http://excelexperts.com/moving-data-rows-columns-depending-unique-conten...

Pls c attached sheet. I have tried to solve it using formula only (no macros as it would need more involvement).

Vishesh's picture

Filter/Find in Array

The following piece of code can be run from any general module. This code extracts all array elements based on the search criteria. You can also search the entire array element or part of it depending on the 3rd parameter of the function if its set to True or False.
Vishesh's picture

Count Array Dimensions

The following piece of code gives the number of dimensions an array has. In the TestRun procedure a range is assigned to variant and that variant is passed to GetArrayDimensions function as a parameter. GetArrayDimensions function returns the number of dimensions in an array. If the range has only one cell then it returns 0 as its not an array; if it has more than one cell its an array in which case it returns 2.
Vishesh's picture

Create In-Cell Chart in Excel using VBA

Paste the following code in a general module and pass the required parameters to create an chart in a cell. This code however works with Excel 2007 onwards.

In-Cell Chart

Vishesh's picture

Transpose Back

Solution for problem on url http://excelexperts.com/re-arrange-excel-data

Paste the following code in any module and run the Test procedure

Sub Test()
    Call TransposeBack(Sheet1.Range("A3:D10"), Sheet1.Range("I1"))
End Sub
 
Sub TransposeBack(rngData As Range, rngTarget As Range)
    Dim rngHeader       As Range
    Dim rngId           As Range
    Dim rngCell         As Range
    Dim rngDest         As Range
    Dim lngRept         As Long
 
    Set rngDest = rngTarget.Offset(1)
 
    With rngData
        Set rngHeader = Intersect(.Rows(1), .Rows(1).O
Vishesh's picture

Code generated ComboBox (ActiveX)

Manually add a combobox to Activesheet and right click to see its properties.
Vishesh's picture

Web Query Solution

Solution for problem posted on url:

http://excelexperts.com/automating-pulling-data-website

Please use the attached xl sheet. Change the symbol and click the button to see

Vishesh's picture

Copy Picture from Web to Excel

The following code pastes the picture from Web to the Excel range. The two parameters required by the function are the URL of the picture and address of target Excel range.
Vishesh's picture

Array to speed up (Range vs Array)

Below two procedures are different ways of populating a range of cells. The one at the bottom using arrays is the faster one. We can use the same to do processing/calculations in arrays and then put the calculated data back to range to speed up the process.
Vishesh's picture

Using Array to refer to multiple sheets

The following example code deletes multiple sheets in one go.
Sub DeleteMultipleSheets()
    Application.DisplayAlerts = False
    With ThisWorkbook.Worksheets(Array("Sheet2", "Sheet3"))
        .Delete
    End With
    Application.DisplayAlerts = True
End Sub
Vishesh's picture

Abbreviated Month name

DO NOT take first 3 characters from a month name to get an abbreviated month name. This can give you duplicate results in some languages as first 3 characters of two months may be same.
I have encountered this with the Czech language.

So, use the following:

If the month is 1 i.e. January

So, to get abbreviated month name ALWAYS use

Monthname(1, True)

This will always return standard abbreviated month name.

Vishesh's picture

Deleting all charts & shapes on a sheet

To delete all charts
sub DeleteAllCharts()
Sheet1.ChartObjects.delete
End Sub
To delete all shapes (this includes charts as well)
sub DeleteAllShapes()
Sheet1.Shapes.SelectAll
Selection.Delete
End Sub
Syndicate content