You are here:

Excel/Macro: Comma between values when value is 100 and above


Successor macro
Successor macro  
QUESTION: I have a macro (see image "Successor Macro") which works OK when in cell(s) “A” the value is lower than 100. Example: when there are multiple values which the macro collects, then I get perfectly 90,93,95, 97

But when the value in cell(s) “A” have a value of 100 and above then the macro will not put a comma anymore between each value: All the values will be put at “together”  See image: "Successor" : In this image you see that when I hit the "ID" button (W7) all the successors ID will be collect. For the deliverable's 1- till 5 the macro puts nicely a comma between the different values (W15). But in cell W24 the macro don't put comma's between the values anymore.

I hope that you can help me with this.

ANSWER: Hi Ellert,

Can you please post the code as text so I don't have to type it?

And the data too?

---------- FOLLOW-UP ----------

QUESTION: Jan Karel Pieterse,

the initial code which i used was:
Sub GetSuccessors()
  Dim LR As Long, a As Long
  Dim SCC_col, SCC_row As Long
  Dim succRang As Range
  Dim Hold
  Dim c As Range
      Set succRange = ActiveSheet.Buttons(Application.Caller).TopLeftCell
      LR = Cells(Rows.Count, 1).End(xlUp).Row
      Range(succRange.Offset(1, 0), succRange.Offset(LR - succRange.Row, 0)).ClearContents
      For a = succRange.Row + 1 To LR Step 1
        Hold = ""
        For Each c In Range(succRange.Offset(1, -3), succRange.Offset(LR - succRange.Row, -1))
         If ((c.Value = Cells(a, 1)) And Cells(a, 1) <> "") Then
         Hold = Hold & Cells(c.Row, 1).Value & ","
         End If
        Next c
        If Right(Hold, 1) = "," Then
         Cells(a, succRange.Column) = left(Hold, Len(Hold) - 1)
        End If
        Hold = ""
      Next a
End Sub

At this moment I have changed the following in the macro:

If Right(Hold, 1) = "," Then
       With Cells(a, succRange.Column)
         .NumberFormat = "@"
         .Value = Left(Hold, Len(Hold) - 1)
       End With
   End If

And this seems to be working for now. so at this moment i am ok.

Ah, now I get it. if you use the comma as a separator, Excel thinks you are entering numbers with a thousands separator in them and then just puts the number in  without the thousands separator. It would have worked if you would have used a different separating character,such as a pipe (|).
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Jan Karel Pieterse


Excel and Excel/VBA questions


Excel MVP

Self employed Excel developer

Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 All rights reserved.