Saturday, 6 July 2013

Add Data into Excel-2007 With VBA Form


Excel-2007 Macro Enabled File is available to download at the end of page.

When you open this file, it will look like shown in below image.

When you click on button, it will open VBA form which counts last free line and jump on it to insert data.
he Form will look like shown in below image.


To find the coding of this form click on right click on sheet name and select "View Code"

Button is assigned with below macro which then open up the form.

Sub OpenCourseBookingForm()
    UserForm1.Show
End Sub


Below is the function which finds the Last Empty Cell for the given sheet name

Private Function Get_Empty_Cell_Index(ByVal SheetName As String) As Long
    On Error GoTo Last
    Dim Index As Long
    Index = 11
    ActiveWorkbook.Sheets(SheetName).Activate
    Range("A" & Index).Select
    Do
        If IsEmpty(ActiveCell) = False Then
            ActiveCell.Offset(1, 0).Select
            Index = Index + 1
        End If
    Loop Until IsEmpty(ActiveCell) = True
    Range("A" & Index).Select
    GoTo Last_1
Last:
    MsgBox ("Sheet:" & SheetName & ": Cell No:" & Index & " - " & Err.Number & ":" & Err.Description)
    Index = -1
Last_1:
    Get_Empty_Cell_Index = Index
End Function


while below code is used to count Next Number in sequence for the given sheetname

Private Function Get_NextNo(ByVal SheetName As String) As Long
    Dim NextNo As Long
    ActiveWorkbook.Sheets(SheetName).Activate
    Range("A11").Select
    Do
        If IsEmpty(ActiveCell) = False Then
            NextNo = ActiveCell.Value + 1
            ActiveCell.Offset(1, 0).Select
        End If
    Loop Until IsEmpty(ActiveCell) = True
    Get_NextNo = NextNo
End Function




Download File VBA Application File




Wednesday, 16 January 2013

How to Retrieve Data Using Stored Procedure, VB ASP.NET, SQL Server



Below is the  code to create Stored Procedure in SQL Server
procedure is created with name "ActiveFaculties"
------------------------------------------------------------

CREATE PROCEDURE dbo.ActiveFaculties
@Status nchar(10)
AS
SELECT        ID, Name
FROM            Faculty WHERE Status=@Status

Return




Below is the code to diaplaying how to use Stored Procedure to get Data
A page contains one Panel control in which data will be added....
-------------------------------------------------------------------------

Imports System.Data.SqlClient

Partial Class Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call_Stored_Proc()
    End Sub


    Protected Sub Call_Stored_Proc()
        Dim Cn As SqlConnection
        Dim Cmd As SqlCommand
        Dim Dr As SqlDataReader

        Cn = New SqlConnection("Data Source=ServerName\your database;Initial Catalog=Attendance;Integrated Security=True")
        Cn.Open()
        Try
            With con

                Cmd = New SqlCommand("ActiveFaculties", Cn)
                Cmd.CommandType = Data.CommandType.StoredProcedure
                'Passing parameter to the argument to get specific data...
                Cmd.Parameters.Add("@Status", Data.SqlDbType.Char).Value = "INACTIVE"
                Dr = Cmd.ExecuteReader
                If Dr.HasRows Then
                    While Dr.Read
                        'Add User's ID and Name in Panel1
                        Panel1.Controls.Add(New LiteralControl(Dr("ID") & vbTab & Dr("Name") & "
"))
                    End While
                End If
                Dr.Close()
            End With
        Catch ex As Exception
            Response.Write(ex.Message)'Shows Error , If any
        Finally
            cn.close
        End Try
    End Sub
End Class


---------------------------------------------------------------------------------------------
I hope above code will help you in designing Stored Procedure to retrieve data from the table
I am always open to solve query.....

Thursday, 5 January 2012

Convert Number in to Word up to 99 crore in EXCEL

Below is the function which gives you Rupees in Word




Function GetWord(ByVal Num)
    Dim InWord As String
    Dim Paisa As String
    Dim x As Integer
    Paisa = ""
    InWord = ""
    x = InStr(Num, ".")
    If x > 0 Then
        Paisa = GetTens(Left(Mid(Num, x + 1) & _
                  "00", 2))
              Num = Trim(Left(Num, x - 1))
              Paisa = Paisa & " Paisa"
    End If
    
    Select Case Len(Num)
        Case 0
            InWord = " Zero "
        Case 1
            InWord = GetDigit(Num)
        Case 2
            InWord = GetTens(Num)
        Case 3
            InWord = GetHundreds(Num)
        Case 4
            InWord = GetHundreds(Num)
            Num = Left(Num, 1)
            InWord = GetDigit(Num) & " Thousand " & InWord
        Case 5
            InWord = GetHundreds(Num)
            Num = Left(Num, 2)
            InWord = GetTens(Num) & " Thousand " & InWord
        Case 6
            InWord = GetHundreds(Num)
            x = Right(Left(Num, 3), 2)
            InWord = GetTens(x) & " Thousand " & InWord
            Num = Left(Num, 1)
            InWord = GetDigit(Num) & " Lac " & InWord
        Case 7
            InWord = GetHundreds(Num)
            x = Right(Left(Num, 4), 2)
            InWord = GetTens(x) & " Thousand " & InWord
            Num = Left(Num, 2)
            InWord = GetTens(Num) & " Lac " & InWord
        Case 8
            x = Right(Num, 3)
            InWord = GetHundreds(Num)
            x = Right(Left(Num, 5), 2)
            InWord = GetTens(x) & " Thousand " & InWord
            x = Right(Left(Num, 3), 2)
            InWord = GetTens(x) & " Lac " & InWord
            Num = Left(Num, 1)
            InWord = GetDigit(Num) & " Crore " & InWord
        Case 9:
            Dim wrd As String
            wrd = Num
            x = Right(Num, 3)
            InWord = GetHundreds(Num)
            Num = Num / 1000    'Number length is greater then 8 so number must be truncated
            x = InStr(Num, ".") 'to length <=8
            Num = Trim(Left(Num, x - 1))
            x = Right(Num, 2)
            InWord = GetTens(x) & " Thousand " & InWord
            x = Right(Left(Num, 4), 2)
            InWord = GetTens(x) & " Lac " & InWord
            Num = Left(Num, 2)
            InWord = GetTens(Num) & " Crore " & InWord
        Case Is >= 10:
            InWord = "Rupees >= 100 Crore"
            
    End Select
    If InWord <> "Rupees >= 100 Crore" Then
        InWord = "Rupees " & InWord
        If Paisa <> "" Then
            InWord = InWord & " And "
        End If
        GetWord = InWord & Paisa & " Only"
        Else
        GetWord = InWord
    End If
End Function


      '*******************************************
      ' Converts a number from 100-999 into text *
      '*******************************************
  
      Function GetHundreds(ByVal MyNumber)
          Dim Result As String
          If Val(MyNumber) = 0 Then Exit Function
          MyNumber = Right("000" & MyNumber, 3)
          ' Convert the hundreds place.
          If Mid(MyNumber, 1, 1) <> "0" Then
          
              Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
          End If


          ' Convert the tens and ones place.
          If Mid(MyNumber, 2, 1) <> "0" Then
              Result = Result & GetTens(Mid(MyNumber, 2))
          Else
              Result = Result & GetDigit(Mid(MyNumber, 3))
          End If
          GetHundreds = Result
      End Function


      '*********************************************
      ' Converts a number from 10 to 99 into text. *
      '*********************************************
     Function GetTens(TensText)


          Dim Result As String
          Result = ""           ' Null out the temporary function value.
          If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
              Select Case Val(TensText)
                  Case 10: Result = "Ten"
                  Case 11: Result = "Eleven"
                  Case 12: Result = "Twelve"
                  Case 13: Result = "Thirteen"
                  Case 14: Result = "Fourteen"
                  Case 15: Result = "Fifteen"
                  Case 16: Result = "Sixteen"
                  Case 17: Result = "Seventeen"
                  Case 18: Result = "Eighteen"
                  Case 19: Result = "Nineteen"
                  Case Else
              End Select
          Else                                 ' If value between 20-99...
              Select Case Val(Left(TensText, 1))
                  Case 2: Result = "Twenty "
                  Case 3: Result = "Thirty "
                  Case 4: Result = "Forty "
                  Case 5: Result = "Fifty "
                  Case 6: Result = "Sixty "
                  Case 7: Result = "Seventy "
                  Case 8: Result = "Eighty "
                  Case 9: Result = "Ninety "
                  Case Else
              End Select


              If Right(TensText, 1) > 0 Then
              Result = Result & GetDigit _
                  (Right(TensText, 1))  ' Retrieve ones place.
                  End If
          End If
          GetTens = Result
      End Function


      '*******************************************
      ' Converts a number from 1 to 9 into text. *
      '*******************************************

      Function GetDigit(Digit)
          Select Case Val(Digit)
              Case 0: GetDigit = "Zero"
              Case 1: GetDigit = "One"
              Case 2: GetDigit = "Two"
              Case 3: GetDigit = "Three"
              Case 4: GetDigit = "Four"
              Case 5: GetDigit = "Five"
              Case 6: GetDigit = "Six"
              Case 7: GetDigit = "Seven"
              Case 8: GetDigit = "Eight"
              Case 9: GetDigit = "Nine"
              Case Else: GetDigit = ""
          End Select
      End Function


To Use this function you have to use VB Editor in your Excel File.
Right Click on Sheet Name (Default is SHEET1) and in it select View Code


Now you'll have VB Editor.
Right Click on VBAProjetc  and select Insert.
in Insert select Module.
Now, you'll have Module1.
Double click on Module1 to open it.
Now, paste above functions.

Now, you have successfully created InWord function to convert number into word.






Tuesday, 3 August 2010

abt cooking

Nowadays I am learning different cooking foods with ready to cook packets.

Yesterday I coocked Paneer Tikka and Paneer Butter Masaala.

Before it, few days ago I coocked Chinese Manturian.

Just adding image

Wednesday, 6 January 2010

My Last day in UK

Today is 6th Jan. 2010....
last night i have njoyed a lot......because last night it heavy snowfall
and we(Me, joyal, rutvij, karmesh, yogesh, sonu) played in snaw a lot......

I have decided to go back to India.
Because My dad is too badly ill, I am unable to get good job, wasting of time and money.
Its awesome experience of UK Life, I loved to leave in UK but just for few time not for complete life.
I love UK's cold whether.

Sunday, 3 January 2010

My First blog.....

r8 now i m in UK.....Date:02/01/09 Time:07:32PM
and i have just started to write in blog.....
nothing more to write....
hi to every one....and to all my friend...

Search This Blog