Concatenate if equal too..
-
-
-
Re: Concatenate if equal too..
ok i am doing it wrong.
i need it to check if column I has value "-" and if it does i need it to concatenate row H:J, in that row only
how do i do this? -
-
Re: Concatenate if equal too..
Okay that worked awesome, but i really need it to delete I1 and J1 when it puts the cells together in H1?
is that possible? -
-
-
-
-
Re: Concatenate if equal too..
So are you!
-
Re: Concatenate if equal too..
Code
Display MoreSub concatenateagain() Dim c As Range For Each c In Selection If Columns("H:H") = "" Then Else Columns("B:B") = c.Offset(, 1).Value & c.Value & c.Offset(, 1).Value c.Offset(, 1).Delete Shift:=xlToLeft c.Offset(, -1).Delete Shift:=xlToLeft End If Next c End Sub
this wont work....what is wrong with my code??
there has got to be an easier way to do what i need....i am running four macros just to get to one point in order to have a mail merge.... :p -
-
Re: Concatenate if equal too..
Newt,
Let's go back to the start on this.
When you run the macro, is there a requirement to select a certain range? Will the program do odd things if the wrong selection is made?
As an object, Selection can have many different collections, e.g. Areas, Rows, Columns, Cells. I always find it useful to declare to VBA exactly which collection you want to use, i.e.
Within your loop through (presumably) each cell in Selection (which from this snippet of code we can't tell if it's several cells in a row, several cells in a column, or what), every time you go through the loop you are checking (or appear to be attempting to check) the same thing - is the whole of column H empty. Are you trying to check the whole of column H for being empty (in which case you would need different code, and it seems a bit pointless doing the same thing many times over) or a specific cell in column H?Similarly, you then appear to be attempting to copy the whole of column C, column B, then column C again into column B (I assume one of the two is a misprint and should be (, -1) instead of (, 1).
It would make things much easier if we could have sight of a bit of your data to see what you're trying to achieve, but let me assume that you have a range of data, over a varying number of rows, and you want to concatenate 3 cells iinto column B if the cell in column H is empty, and that you have selected a range of cells covering column A only:
Code
Display MoreDim rngSelection As Range Dim rngCell As Range Set rngSelection = Selection For Each rngCell in rngSelection.Cells If Len(rngCell.Offset(0, 7).Value) > 0 Then rngCell.Offset(0, 1) = rngCell.Offset(0, 1).Value & rngCell.Offset(0, 2).Value & rngCell.Offset(0, 3).Value Range(rngCell.Offset(0, 2), rngCell.Offset(0, 3)).ClearContents End If Next rngCell
I have avoided deleting cells and shifting to the left, as it tends to corrupt the structure of the rest of your data.I may well be extremely wide of the mark here, and if I am perhaps you could post up a sample workbook so that we can get a bit better idea of your process.
Regards,
Batman. -
Re: Concatenate if equal too..
ok i attached a small sample of what i am dealing with.
i need to make this into a mail merge format.
so i need to separate the cell into different fields.
there is about 1500 fields i have to go through so manual is not an option and as you can see some address fields have dashes and streets with two names so the column to text does not work very well.
if any one can come up with a better idea...that would be great.
right now i am parsing the data from column to text and then from there concatenating the street numbers...
help.
thanks -
Re: Concatenate if equal too..
Newt,
Now I'm really confused!
Up to now your posts have indicated that you want to check the contents of column H for being empty then, if not, concatenate the contents of 3 unspecified columns. What you have attached is already concatenated, there is no data in any column other than H and you now seem to want to split a single column (H) into sections.
Have we moved to a different part of your overall process? If so, do you still need the original request answering?
With regard to the set of data that you have posted, how easy it will be to break it down in a consistent manner will depend on the structure of the data in the cells.
My first thought is to loop backwards through the cell. As there appears to be a postcode (or whatever you call it) at the end of each record, and that includes a single space, you should be able to separate out the postcode by searching for the second space from the right.
After that you seem to have a province, containing only a single word, so you could separate that out by searching for the third space from the right.
Before that you have a city; if that is always a single word searching for the fourth space from the right will find that.
That should then only leave the house number and street as the remainder of the field to go into a separate cell.
If you think the logic above will work, let me know and I will add some code to do it.
Regards,
Batman. -
Re: Concatenate if equal too..
your right i made this extra confusing.
i was trying to figure it out myself and i got as far as separating all the data, then i was left with the street number separated into three cells when they had a "-" so i needed to concatenate if it had a dash.
then after i did that i ended up with some streets having a two word name and when that happend then the postal code would go into column "H" so i thought i could right a code that looked to see if column "H" was empty and if not concatenate the street names.
i probably did it the super hard way so i thought i would attach a sample of my project and see if there was an easier way.
i am trying to do exactly what you said and if you can right a code that is much easier then that would be awesome! -
Re: Concatenate if equal too..
Newt,
Try the attached. It seems to work for the range of data in your sample list of addresses.
Hope this helps.
Regards,
Batman. -
-
Re: Concatenate if equal too..
oh course....leave it to you to make it SUPER easy....wow.
some days i think i am smart....today not so much..haha
YOU are awesome and you just made my job ten times easier. :ole:THANK you!!!!
Kristen
-
Re: Concatenate if equal too..
Glad to have been of help.
Regards,
Batman.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!