Excel through VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moni1
    New Member
    • Oct 2013
    • 2

    Excel through VB

    Hi,
    I am new to visual basic, now only i am learning, pls give me solution and codes,
    i need to define # rows and columns in excel based on input given by user in vb, i tried the
    below code to define only row but i couldn't able to success it,
    i using input box,FOR loop when user enter the row value in input box automatically the rows should be alloted
    and after alloted rows fully fill with my name "MOHAN"

    for example
    if i give row value in input box 5 means then automatically 5 rows filled up with my name called MOHAN and
    if i enter row value 80 then 80 rows filled with MOHAN


    CODES:

    Code:
    Public oExcel As New Excel.Application
    Public oBook As Excel.Workbook
    Public oSheet As Excel.Worksheet
    
    
    Private Sub Command1_Click()
    Set oExcel = CreateObject("Excel.Application")
    Set oBook = oExcel.Workbooks.Add
    Set oSheet = oBook.Worksheets(1)
    Dim n As Integer
    Dim row As Integer
    n = InputBox("Enter how many rows you want", "Excel")
    For row = 0 To n
    Print "mohan"
    Next row
    oSheet.Range("A1").Value = "NAME"
    oExcel.Visible = True
    End Sub
    From the above code i just created only column name but after that i don't know how to fill up my name into
    excel rows based on my row value. Give me the right solution.
    Last edited by Rabbit; Nov 3 '13, 10:52 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Compare line 16 to line 14. Line 16 is the correct way to assign a value to a cell. Not line 14.

    Comment

    Working...