vendredi 27 février 2015

concatenate a range with macro, with conditional to omit empty cells - excel vba

I am trying to concatenate a range of input cells in a column, to one output cell in a separate worksheet. This is repeated with different ranges to different cells. e.g. range(A1:5) -> cell(B1) ; range(A6:10) -> cell(B2) ; ...etc.


I currently make use of the concatenate formula in the output cell, but I feel it is messy when a cell in the range to be concatenated is empty (the delimiter in the function is a ","). As an example, there is a possibility that the output cell becomes ",,x,y,,,,z,",etc as a result of empty cells. I thus need to incorporate a conditional statement into a macro to ignore empty cells, and concatenate the rest with delimiter ",".


An example of desired output would be: "x,y,z". Neat.


Being a vba amateur and having searched around, all I could find is functions to do this (hence no initial code). I would prefer a 'button' object so that the user can finalise the process in a controlled way.


Any help would be appreciated.


Regards,


Aucun commentaire:

Enregistrer un commentaire