+ Reply to Thread
Results 1 to 8 of 8

Get value and add next cell

  1. #1
    Registered User
    Join Date
    02-08-2004
    Posts
    23

    Get value and add next cell

    Hi,

    I have a range D8:D104 what I would like to do is get the value for each cell and add &servicetype1= plus the cell value etc and move to the next cell

    the string looks like:
    &servicetype1=first cell value&servicetype2=second cell value etc

    is this possible?

    Thanks,

    Sanj

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    Quote Originally Posted by sanjay
    Hi,

    I have a range D8:D104 what I would like to do is get the value for each cell and add &servicetype1= plus the cell value etc and move to the next cell

    the string looks like:
    &servicetype1=first cell value&servicetype2=second cell value etc

    is this possible?

    Thanks,

    Sanj
    hit = CONCATENATE()

    then hit the = sign beside the formula bar and work from there

  3. #3
    Registered User
    Join Date
    02-08-2004
    Posts
    23
    Sorry Dave, I must not have been clear, I know how to do this in the worksheet but would like to do this via VB Script.

    Regards,

    Sanj

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    Oh! Okay, hold on a sec


    Here's how to do it with CONCATENATE with VBA

    Sub Button1_Click()
    Range("D1") = "Cell A1" & [A1] & "&" & "CellA2" & [A2]
    End Sub


    You want some sort of loop or something right?, so you can do it 98 times?

  5. #5
    Registered User
    Join Date
    02-08-2004
    Posts
    23
    Thanks Dave,

    Yes I would like it to loop for a defined value which I can set.

    I probably need a Do While Loop:

    Counter = 0

    Do While Counter < 98
    Counter = Counter + 1
    myvalue = "ServiceType" & Counter & "=" & [A1]
    Loop

    Then somehow I need to offset from the existing cell

    Regards,

    Sanj

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    here's a great function I have found....



    Public Function MultiCat(ByRef rRng As Excel.Range, _
    Optional ByVal sDelimiter As String = "") As String
    Dim rCell As Range
    For Each rCell In rRng
    MultiCat = MultiCat & sDelimiter & rCell.Text
    Next rCell
    MultiCat = Mid(MultiCat, 1 - (Len(sDelimiter) > 0))
    'Call as =MultiCat(A1:A5)
    'you can add a delimiter if you wish:
    ' =MultiCat(A1:A5,",")

    End Function

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    I don't know how well this will work because of the amount of characters involved

  8. #8
    Registered User
    Join Date
    02-08-2004
    Posts
    23
    Dave that's a useful function and it also works for what I require plus I have also got my previous VB Script works !

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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