Results 1 to 4 of 4

VBA problems when copying from online code

Threaded View

  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.

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