Monday, June 27, 2016

A Simple And Useful Userform (Address Book)

          I updated the userform that I did previously to run it in all version of Excel.

With this userform ;
- Data can be added
- Data can be deleted
- Data can be edited
- Data can be searched on the sheet
- Listbox can be filled and emptied with button.
- Listbox can be scrolled with the spin button.

          Id numbers are generated automatically  when new record is added to the worksheet and  when record is removed.
The listbox is empty when the userform is opened.
The entered value in the searching box can be searched  on the worksheet. listbox are filled with the found results .

          The listbox column widths is automatically adjusted according to the widths of the sheet's column with Vba codes.

The Address Book (Userform's Listbox Contains 12 Column)

            A follower of the blog wanted this example.
Maximum 10 columns can be added to the listbox with ListBox1.AddItem Method. To solve this problem, we have filled the listbox an array.

            m = m + 1
            ReDim Preserve myarr(1 To 12, 1 To m)
            For j = 1 To 12
                myarr(j, m) = .Cells(k.Row, j + 1).Value
            Next j
            Set k = .Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row).FindNext(k)
        Loop While Not k Is Nothing And k.Address <> adrs
        ListBox1.Column = myarr

Also we added a new macro  to avoid duplicate data entry in Column B (names in this column).

Thursday, June 23, 2016

Adding Data Into The Closed Workbook With Userform

Simultaneously Adding Record  To Two Different Workbooks (Open And Closed Workbooks) With The Userform

           For his process ,we have used Ado Connection again.

With userform in the first workbook,the data can be added easily into the closed workbook without opening workbook.

Tuesday, June 14, 2016

Excel Vba Dependent Drop-Down Lists With ADO

Filter With Dependent Combo Boxes And Pull Filtered Results Into Listbox

            We used the dependent combo boxes (4 combo boxes) in this study again. We filtered the data on the sheet with combo boxes,and pulled filtered results into listbox. If desired ,the filtered data can be copied with button to other pages.

To be able to faster the filtering process, we used ADO  (ActiveX Data Objects). ADO is a subset of the Visual Basic programming language specifically designed for communicating with databases.

To avoid compatibility problems between 32bit and 64bit ,we organized codes as follows :

When the cursor hovers on combo boxes, they are opened as automatically. For this ,following codes :

Our template is ready for use .

Friday, June 10, 2016

Excel Dependent Combo Boxes

             In this example, we will create a userform that contains dependent combo boxes and a textbox. We will use  this userform to enter the data  into cells as fastly.

The UserForm will be opened automatically when any cell in "Column A" is selected.

            The important point in this template ; by creating a dependency between combo boxes,  selectively choices can be limited. When the user selects Supplier from first drop-down list ,as a result, Category can be selected according to supplier from second drop-down list. Later ,based on selected category ,Product can be selected  from third drop-down list. Code of product is added in textbox as automatically.

- Firstly, we need to create lists of combo boxes . For this we created lists in other sheet. Heads of lists : Supplier | Category | Product | Code

- Secondly ,we need to define names for lists. When lists are subject to updates, we can use a dynamic range instead. To create a dynamic range name for the Supplier list, do the following:

1- Click Define Name in the Defined Names group on the Formulas tab. (In Excel 2003, Choose Name from the Insert menu and choose Define)
2- Name the list Supplier.
3- Enter the following formula in the Refers To control : =OFFSET(Database!$A$2;0;0;COUNTA(Database!$A:$A)-1)
4- Click OK.

We repeated steps 1 through 4 to create dynamic lists for the other three lists:
Category: =OFFSET(Database!$B$2;0;0;COUNTA(Database!$B:$B)-1)
Product: =OFFSET(Database!$C$2,0,0,COUNTA(Database!$C:$C)-1)
Code: =OFFSET(Database!$D$2,0,0,COUNTA(Database!$D:$D)-1)

Later , we entered codes into VBE (Visual Basic Editor)  .

Tuesday, June 7, 2016

Inserting An Animated Gif Into Worksheet

Displaying An Animated Gif Image In Web Browser Control

            The animated gif can be added in Excel sheet.
This can be done through Control Toolbox, Design Mode and “Microsoft Web Browser” Control.

To insert the control:
  • Go to View > Toolbars > Control Toolbox
  • Activate Design mode
  • Choose the last button (hammer picture), then select "Microsoft Web Browser"
  • Draw a frame for the image (animated gif)
  • Disable Design mode and the toolbar
  • Paste the following code in the VBA editor:

Private Sub Worksheet_Activate()
WebBrowser1.Navigate "about:<html><body scroll='no'><img src=" & ThisWorkbook.Path & "\ani.gif> </img></body></html>"
End Sub

We need to construct a image file path as correctly.So you need something like this:

WebBrowser1.Navigate "about:<html><body scroll='no'><img src=' C:\animated.gif '> </img></body></html>"

Change the active sheet of the workbook, and then turn on the sheet containing the animation, to see  if it works.

The animated gif image can be added from any web address.For this,the following code can be used :
Private Sub Worksheet_Activate() WebBrowser1.Navigate "about:<html><body scroll='no'><img src='http://'> </img></body></html>"
End Sub