CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Text1 to excel

  1. #1
    Join Date
    Aug 2009
    Posts
    98

    Text1 to excel

    Hello everybody,

    I need your help again on this code:
    Code:
    Dim xlExcel     As New Excel.Application
        
        xlExcel.ActiveWorkbook.Sheets(1).Cells(2, 4).Value = Text1.Text
        xlExcel.Application.DisplayAlerts = False
        xlExcel.ActiveWorkbook.SaveAs "C:\Documents and Settings\test.xls"
        xlExcel.ActiveWorkbook.Close
        xlExcel.Quit
        Set xlExcel = Nothing
    I would like the code to found in column 4 the last value insert, and right down the new value in the first empty cell just under.

    How can I do this please?

    Thanks again.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Text1 to excel

    I don't understand. That looks like it changes (2,4) to Text1
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2009
    Posts
    98

    Re: Text1 to excel

    Yes, you are right,

    But now, I want to change it to the first cell that is empty in column 4, starting from line 2, going down.

  4. #4
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Text1 to excel

    You can use either of these technioques to determine the last used row/cell. It best to go from the bottom up as if you go from the top down it may not be the last used cell as it only looks at empty cells.


    Code:
    Dim oRange As Range
    Set oRange = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell)
    MsgBox oRange.Address
    
    'Or
    MsgBox Range("D65536").End(xlUp).Row + 1
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured