Monday, May 29, 2017

Play Musical Notes In Excel

           Musical notes (piano notes) can be played with buttons and functional keys in Excel.

- Ago, we added buttons to the worksheet .Then ,we assigned the macros to these buttons to play the music notes(.wav files) that are in the same place as the workbook. Example ;

  Private Sub CommandButton2_Click()
  Call sndPlaySound32(ThisWorkbook.Path & "\a1.wav", 0)
  End Sub

- If desired music notes can be played with function keys F1, F2 etc. We used the following codes for this process :

Sub A_1()
    Call sndPlaySound32(ThisWorkbook.Path & "\a1.wav", 0)
End Sub
Sub auto_open()
Application.OnKey "{F1}", "A_1"
End Sub

Sunday, May 21, 2017

Product Filtering Between Two Dates Using Userform

Between the selected dates ,product-based filtering can be done using the userform.

        When the dates (start date,end date) are entered in text boxes and if report button is pressed  the userform  elongation effect is activated and listbox appears.
When choosing a date to add into text boxes,the date userform was used instead of date picker control :

The found results are listed on the listbox.

Saturday, May 20, 2017

Excel Vba Class Module Examples


          In three separate workbooks, we have created useful userforms using class modules :

- Fast percentage calculation userform
- Product discount calculation according to quantity,price and percent rate
- Hiding / displaying the columns of sheet (column management with userform)

Wednesday, May 17, 2017

Find Data Between Two Dates In Excel Vba

          Records in between two specific dates easily can be filtered using drop-down lists .
Ago ,drop-down lists (combo boxes) were filled with unique values as ascending order using ADO connection.  Thus, it is easier to choose between the dates on the worksheet. The used codes for this :

Set con = CreateObject("adodb.connection")
    #If VBA7 And Win64 Then
con.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.FullName & ";extended properties=""excel 12.0;hdr=yes"""
con.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.FullName & ";extended properties=""excel 8.0;hdr=yes"""
    #End If       
Set rs = CreateObject("adodb.recordset")
sorgu = "select Date from [Page1$] group by Date"
rs.Open sorgu, con, 1, 1
While Not rs.EOF
Sheets("Page1").ComboBox1.AddItem VBA.Format(rs("Date").Value, "")
Sheets("Page1").ComboBox2.AddItem VBA.Format(rs("Date").Value, "")

Then ,the data between the two dates selected from combo boxes is filtered through Vba codes :

 lngStart = VBA.CDate(Sheets("Page1").ComboBox1) 'assume this is the start date
    lngEnd = VBA.CDate(Sheets("Page1").ComboBox2) 'assume this is the end date
    If lngStart > lngEnd Then
    MsgBox "The Start Date Can Not Be Bigger Than The End Date.", vbCritical, ""
    Exit Sub
    End If
    Sheets("Page1").Range("B:B").AutoFilter field:=1, _
    Criteria1:=">=" & lngStart, Operator:=xlAnd, Criteria2:="<=" & lngEnd

The filtered data can be copied to other sheet if it wished.