Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel / Unique ID

Posted on 2010-08-14
8
Medium Priority
?
351 Views
Last Modified: 2012-05-10
Hi Experts,

I have tried to obtain code off the net and make changes to it, but nothing is working. I have a userform
that works great for entering data into sheet 1. I was using a basic formula in column L to concatenate fields together to make a unique ID. When I copy this formula down it then makes the userform write to the wrong row in sheet 1 when data is entered.
I'm wondering is it possible to automatically concatenate column (E, C, and K) together using VBA according to when the rows of data are entered. Is there some kind of change event in VBA that can achieve this in column L? Is it possible to have it automatically do this without any user interference or button etc.

Many Thanks in advance, I have attached a sample sheet in excel.
SampleUniqueID.xlsx
0
Comment
Question by:JKCC
  • 3
  • 3
  • 2
8 Comments
 
LVL 45

Expert Comment

by:patrickab
ID: 33438649
JKCC,

The file does not contain a UserForm nor does it contain any VBA code. Please upload your file with both the UserForm and the code you are currently using - albeit with errors.

Patrick
0
 

Author Comment

by:JKCC
ID: 33438693
I can't because it is confidential information. That is why I created a simple dummy attached with a very basic sample. If it is not possible than I will have to look for other ways of achieving this. I'm just really after column L concatenating the 3 fields together as the rows are populated. E.g. as row one is populated than, column L should populate with the concatenation and so on through VBA. Is it that this has to be in the userform or can it be a separate module specificually for sheet1? I currently do the basica formula in sheet1 and not on the userform.

I'm new to all of this and have had lots of help getting this done so I'm still learning ALOT!!!!

Thanks heaps!

0
 

Author Comment

by:JKCC
ID: 33438702
Can it be based on according to column A. So when column A is populated, then column L would generate the concatenation via VBA in the corresponding row etc? I dunno, just a thought. I'm not specifically after a unique ID being generated just the count down and the concatenatin via vba. Hope this helps a little. Anythig to get me started would be great.

Cheers,
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 81

Expert Comment

by:byundt
ID: 33438711
You can use a worksheet event sub that will populate column L without a formula. This sub must be placed in the code pane for the worksheet, and won't work at all anywhere else.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range, rw As Range, targ As Range
Dim n As Long
n = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Rows.Count - 1 'Number of last row with data
Set targ = Union([C2].Resize(n - 1, 1), [E2].Resize(n - 1, 1), [K2].Resize(n - 1, 1))
Set targ = Intersect(targ, Target)
If targ Is Nothing Then Exit Sub

Application.EnableEvents = False
For Each rw In targ.EntireRow.Rows
    With rw
        If Application.CountA(.Cells(3), .Cells(5), .Cells(11)) = 3 Then
            .Cells(12) = Left(.Cells(5), 2) & .Cells(3) & .Cells(11)
        Else
            .Cells(12) = ""
        End If
    End With
Next
Application.EnableEvents = True
End Sub

Open in new window

SampleUniqueIDQ26403446.xlsm
0
 
LVL 45

Accepted Solution

by:
patrickab earned 1000 total points
ID: 33438735
JKCC,

The code below is in the attached file. When a change is made in column 1 of Sheet1, the formula you have specified is placed automatically on the same row in column L.

Patrick
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim celle As Range

With Sheets("Sheet1")
    Set rng = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
    If Not Intersect(rng, Target) Is Nothing Then
        .Cells(Target.Row, 12).FormulaR1C1 = "=CONCATENATE(LEFT(RC[-7],3),"""",RC[-9],RC[-1])"
    End If
End With

End Sub

Open in new window

SampleUniqueID-01.xls
0
 
LVL 81

Assisted Solution

by:byundt
byundt earned 1000 total points
ID: 33438751
Although it didn't make any difference with your sample data, I had the wrong number of characters from column E. It should have been 3 in statement 13.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range, rw As Range, targ As Range
Dim n As Long
n = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Rows.Count - 1 'Number of last row with data
Set targ = Union([C2].Resize(n - 1, 1), [E2].Resize(n - 1, 1), [K2].Resize(n - 1, 1))
Set targ = Intersect(targ, Target)
If targ Is Nothing Then Exit Sub

Application.EnableEvents = False
For Each rw In targ.EntireRow.Rows
    With rw
        If Application.CountA(.Cells(3), .Cells(5), .Cells(11)) = 3 Then
            .Cells(12) = Left(.Cells(5), 3) & .Cells(3) & .Cells(11)
        Else
            .Cells(12) = ""
        End If
    End With
Next
Application.EnableEvents = True
End Sub

Open in new window

SampleUniqueIDQ26403446.xlsm
0
 

Author Comment

by:JKCC
ID: 33439410
Thanks experts...both solutions work great.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 33439754
JKCC - Thanks for the grade and points - Patrick
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question