Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA - concatenate with a loop

Hi guys
I have two macro's.
one tocheck for a status and act accordingly and one to split a full name into three parts.

View the code below:

Sub ConsCodeV3()
Dim c As Range
For Each c In Range("E1:E20")
If c < "CONS" Then
c.Offset(, -3) = UCase(c.Offset(, -2))
c.Offset(, -4) = "ConsCode"
End If
If c = "CONS" Then
c.Offset(, -3) = UCase(c.Offset(, -2))
End If
Next c
End Sub

Sub NameSplit()
Dim rng As Range

For Each rng In Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Range(Cells(rng.Row, rng.Column + 10), Cells(rng.Row, rng.Column + 13)) = Split(rng, " ")
Next rng
End Sub

Now what i want to do is the split names, i want to concatenate them in a specific way. I need to take the last name and truncate down to 4 letters, then add the initials of the first name and any other initials remainging. This then needs to go into Column A.

this will only want to happen for those that have "ConsCode" in column A following the ConsCodeV3() macro.

Is this easily done?


Submitted via EggHeadCafe - Software Developer Portal of Choice
..NET - Writing a self-updating application in C#
http://www.eggheadcafe.com/tutorials...a-selfupd.aspx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - concatenate with a loop


Use a function and pass the variables that are required. In the
function set the return value back to to function name.


Sub ConsCodeV3()
Dim c As Range
For Each c In Range("E1:E20")
If c < "CONS" Then
c.Offset(, -3) = UCase(c.Offset(, -2))
ColB = c.offset(,-3)
ColL = c.offset(,+7)
ColO = c.offset(,+10)
c.Offset(, -4) = NameSplit(ColB,ColL,ColO)
End If

If c = "CONS" Then
c.Offset(, -3) = UCase(c.Offset(, -2))
End If
Next c
End Sub

Function NameSplit(ColB,ColL,ColO)
Dim rng As Range

NameSplit = left(ColB,4) & Coll & ColO
End Function


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=170411

Microsoft Office Help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Concatenate Loop FIRSTROUNDKO via OfficeKB.com Excel Discussion (Misc queries) 4 March 11th 06 12:37 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
I know how to concatenate ,can one de-concatenate to split date? QUICK BOOKS PROBLEM- New Users to Excel 1 July 26th 05 05:07 PM


All times are GMT +1. The time now is 12:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"