Solved

Excel / Unique ID

Posted on 2010-08-14
8
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 250 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 250 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
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 longer labels with horizontal bar charts instead of the vertical column chart.

733 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