Tutorial memasukkan inputbox mjacro ke excell

Thursday, May 23, 20130 comments




Macro, merupakan  suatu bahasa pemrograma yang menggunakan bahasa VBE / VBA (baca Visual Basic Editor / Visual BAsic Application). Macro ini banyak sekali dimanfaatkan oleh para programmer,dari  membuat form nilai, form pendaftaran, bahkan sampai membuat virus (baca : virus macro.)
macro dapat langsung diintegrasikan melalui microsoft office, salah satunya yang paling banyak adalah microsoft excel.

Berikut ini adalah contoh pemanfaatan macro dalam memasukkan data ke dalam excel, dengan mengambil data melalui input box. (Input box dapat dibuat saat pertama kali loading).

   Sub Using_InputBox_Method()
      Dim Response As Integer

      ' Run the Input Box.
      Response = Application.InputBox("Enter a number.", "Number Entry", , 250, 75, "", , 1)

      ' Check to see if Cancel was pressed.
      If Response <> False Then

         ' If not, write the number to the first cell in the first sheet.
         Worksheets(1).Range("a1").Value = Response

      End If

   End Sub
Fungsi diatas, akan dipakai untuk memasukkan suatu nomor pada inputbox. hal ini terlihat pada script
Response = Application.InputBox("Enter a number.", "Number Entry", , 250, 75, "", , 1), yanng artinya akan mengambil nilai dari inputbox yang dimasukkan user.

Fungsi kotak Input
Dalam contoh di bawah, serangkaian pernyataan jika digunakan untuk memeriksa entri. InputBox berada di dalam sebuah loop sementara untuk memungkinkan hal itu terjadi re-shown jika terjadi kesalahan. Jika semua kondisi benar, nomor masuk ditulis ke sel A1 pada worksheet pertama dan loop berakhir.

   Sub Using_InputBox_Function()
      Dim Show_Box As Boolean
      Dim Response As Variant

      ' Set the Show_Dialog variable to True.
      Show_Box = True

      ' Begin While loop.
      While Show_Box = True

         ' Show the input box.
         Response = InputBox("Enter a number.", _
            "Number Entry", , 250, 75)

         ' See if Cancel was pressed.
         If Response = "" Then

            ' If Cancel was pressed,
            ' break out of the loop.
            Show_Box = False
         Else
            ' Test Entry to find out if it is numeric.
            If IsNumeric(Response) = True Then
               ' Write the number to the first
               ' cell in the first sheet in the active
               ' workbook.
               Worksheets(1).Range("a1").Value = Response
               Show_Box = False
            Else
               ' If the entry was wrong, show an error message.
               MsgBox "Please Enter Numbers Only"
            End If
         End If
      ' End the While loop.
      Wend
   End Sub

Setelah Anda menjalankan makro, nomor Anda dimasukkan ke dalam input box adalah dalam sel A1 pada Sheet1.
Selamat mencoba...


Share this article :

Post a Comment

 
Copyright © 2011. EF - net - All Rights Reserved
Proudly powered by Blogger