Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Simple VB question

  • 08-06-2005 04:27PM
    #1
    Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭


    Im relatively new to VB and especially new to using VB in conjunction with Excel.

    Heres a real newbie question:

    Can someone explain to me, maybe even give me a little code snippet, to write a string value into a cell in an excel worksheet please?

    Took me two minutes to figure out how to read from Excel but for the life of me cant get it to write to a worksheet. Its become a blur of .Cells and .Range!!


Comments

  • Moderators, Arts Moderators Posts: 36,204 Mod ✭✭✭✭pickarooney


    If I understand you correctly, you have a string variable whose value you want to copy into a particular cell? The way I'd do it is create a DataObject
    Dim MyDataObj As New DataObject
    Dim MyString As String
    
    MyString = "some stuff"
    
    MyDataObj.SetText MyString
    MyDataObj.PutInClipboard
    
    Range("A1").Select
    
    Selection.Paste
    

    Any use to you?


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    in the end it wasnt quite so complex. it turned out i was just having a bit of a brain fart. thanks for the help man.


  • Closed Accounts Posts: 8,259 ✭✭✭RicardoSmith


    Record a macro and look at the code it produces. Very handy if you get a duh moment.


Advertisement