+ Reply to Thread
Results 1 to 4 of 4

VBA problems when copying from online code

  1. #1
    Registered User
    Join Date
    04-15-2011
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    9

    Question VBA problems when copying from online code

    Hi,

    I have a similar problem to the one solved in the link below.

    http://www.officekb.com/Uwe/Forum.as...ate-like-sumif

    This is involving concatenating several text lines when they show a matching reference. E.G if column a shows "LT_001", then concatenate the comments of all with same referance. I had intended to copy out the formula used, and adjust it to fit my situation, but if I copy the formula into VBA it does not allow me to run the function.

    I have the same problem with most VBA code taken from the internet and can't figure out what I should be doing? I have literally copied the formula as is, bar changing "A7" to "A2". As I am trying to adjust the formula to fit, for the moment my workbook has example data in columns A, B, and C, and a consolidated list of column A in Column G.

    This is the function I have copied from the page:

    Public Function Test(TruckNo) As String
    Dim EndRow As Long
    Dim NN As String
    Dim x As Long

    EndRow = Range("A7").End(xlDown).Row

    For x = 7 To EndRow
    If Cells(x, 1).Value = TruckNo Then NN = NN & Cells(x, 2).Value _
    & " : " & Cells(x, 3).Value & Chr(10)
    Next x

    NN = Left(NN, Len(NN) - 1)

    Test = NN

    End Function

    Do I need to change some of this text in order to make this run?

    As is blindingly obvious, I have no idea what I am doing in VBA, so any help on why I can't get things to work is hugely appreciated.

    Thank you,

    Larisa
    Last edited by LTurnbull; 04-15-2011 at 10:51 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: VBA problems when copying from online code

    It would help to see your workbook/data

    It's a User Defined Function (UDF) so you call it in a cell like a standard Excel function, or in a VBA macro.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    04-15-2011
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    9

    Talking Re: VBA problems when copying from online code

    :: blushes ::

    That really was a bit foolish. Of course it won't run, it's not a macro.

    Thank you very much. It works just as it should.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: VBA problems when copying from online code

    No problem, we all make mistakes.

    It's more foolish not to ask when you need help ... and I bet you won't make that mistake again in a rush :-)

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1