Auto-Increment if Column Already Contains a Certain Value











up vote
0
down vote

favorite












I have a question on how to best accomplish auto incrementation in Excel.



In my sheet, I have two Columns - Column A, which is my ID, and Column E, which is my Workstream (Columns B-D were hidden for ease of read). The Workstream column is a drop-down and contains multiple values.



ID and Workstream



Currently, my ID column (Column A) is based on the following formula:
(My data starts in Row 17)



=IF(E17="","",E17 & "-000-"& TEXT(ROW()-16,"000"))



Here's where it gets tricky for me. I will explain it as best as I can.



What I'm looking to do is alter my formula (or maybe use VBA?) to auto increment, based upon if a value exists in Column A.



If Column A already contains WM-000-001 in Row 17, and a user selects the WM option from the drop-down in Column E, in say Row 19, Column A will automatically populate WM-000-002 in Row 19.



I've also been trying to accomplish the same thing in VBA using Worksheet_Change(ByVal Target As Range), but am still running into a roadblock, as I'm not sure how to correctly code the formula.



If there is an easier way to accomplish this, or if anyone could nudge me in the right direction, it would be much appreciated!










share|improve this question




















  • 3




    Sounds like a job for a relational database.
    – Comintern
    Nov 9 at 17:47










  • Is there any sort of workaround?
    – user7735684
    Nov 9 at 18:02






  • 4




    If you're trying to create a relational database in something that isn't a relational database, everything will be a workaround.
    – Comintern
    Nov 9 at 18:03






  • 1




    sure there is
    – Mathieu Guindon
    Nov 9 at 18:09















up vote
0
down vote

favorite












I have a question on how to best accomplish auto incrementation in Excel.



In my sheet, I have two Columns - Column A, which is my ID, and Column E, which is my Workstream (Columns B-D were hidden for ease of read). The Workstream column is a drop-down and contains multiple values.



ID and Workstream



Currently, my ID column (Column A) is based on the following formula:
(My data starts in Row 17)



=IF(E17="","",E17 & "-000-"& TEXT(ROW()-16,"000"))



Here's where it gets tricky for me. I will explain it as best as I can.



What I'm looking to do is alter my formula (or maybe use VBA?) to auto increment, based upon if a value exists in Column A.



If Column A already contains WM-000-001 in Row 17, and a user selects the WM option from the drop-down in Column E, in say Row 19, Column A will automatically populate WM-000-002 in Row 19.



I've also been trying to accomplish the same thing in VBA using Worksheet_Change(ByVal Target As Range), but am still running into a roadblock, as I'm not sure how to correctly code the formula.



If there is an easier way to accomplish this, or if anyone could nudge me in the right direction, it would be much appreciated!










share|improve this question




















  • 3




    Sounds like a job for a relational database.
    – Comintern
    Nov 9 at 17:47










  • Is there any sort of workaround?
    – user7735684
    Nov 9 at 18:02






  • 4




    If you're trying to create a relational database in something that isn't a relational database, everything will be a workaround.
    – Comintern
    Nov 9 at 18:03






  • 1




    sure there is
    – Mathieu Guindon
    Nov 9 at 18:09













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a question on how to best accomplish auto incrementation in Excel.



In my sheet, I have two Columns - Column A, which is my ID, and Column E, which is my Workstream (Columns B-D were hidden for ease of read). The Workstream column is a drop-down and contains multiple values.



ID and Workstream



Currently, my ID column (Column A) is based on the following formula:
(My data starts in Row 17)



=IF(E17="","",E17 & "-000-"& TEXT(ROW()-16,"000"))



Here's where it gets tricky for me. I will explain it as best as I can.



What I'm looking to do is alter my formula (or maybe use VBA?) to auto increment, based upon if a value exists in Column A.



If Column A already contains WM-000-001 in Row 17, and a user selects the WM option from the drop-down in Column E, in say Row 19, Column A will automatically populate WM-000-002 in Row 19.



I've also been trying to accomplish the same thing in VBA using Worksheet_Change(ByVal Target As Range), but am still running into a roadblock, as I'm not sure how to correctly code the formula.



If there is an easier way to accomplish this, or if anyone could nudge me in the right direction, it would be much appreciated!










share|improve this question















I have a question on how to best accomplish auto incrementation in Excel.



In my sheet, I have two Columns - Column A, which is my ID, and Column E, which is my Workstream (Columns B-D were hidden for ease of read). The Workstream column is a drop-down and contains multiple values.



ID and Workstream



Currently, my ID column (Column A) is based on the following formula:
(My data starts in Row 17)



=IF(E17="","",E17 & "-000-"& TEXT(ROW()-16,"000"))



Here's where it gets tricky for me. I will explain it as best as I can.



What I'm looking to do is alter my formula (or maybe use VBA?) to auto increment, based upon if a value exists in Column A.



If Column A already contains WM-000-001 in Row 17, and a user selects the WM option from the drop-down in Column E, in say Row 19, Column A will automatically populate WM-000-002 in Row 19.



I've also been trying to accomplish the same thing in VBA using Worksheet_Change(ByVal Target As Range), but am still running into a roadblock, as I'm not sure how to correctly code the formula.



If there is an easier way to accomplish this, or if anyone could nudge me in the right direction, it would be much appreciated!







excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 18:00









Mathieu Guindon

39.7k762138




39.7k762138










asked Nov 9 at 17:30









user7735684

104




104








  • 3




    Sounds like a job for a relational database.
    – Comintern
    Nov 9 at 17:47










  • Is there any sort of workaround?
    – user7735684
    Nov 9 at 18:02






  • 4




    If you're trying to create a relational database in something that isn't a relational database, everything will be a workaround.
    – Comintern
    Nov 9 at 18:03






  • 1




    sure there is
    – Mathieu Guindon
    Nov 9 at 18:09














  • 3




    Sounds like a job for a relational database.
    – Comintern
    Nov 9 at 17:47










  • Is there any sort of workaround?
    – user7735684
    Nov 9 at 18:02






  • 4




    If you're trying to create a relational database in something that isn't a relational database, everything will be a workaround.
    – Comintern
    Nov 9 at 18:03






  • 1




    sure there is
    – Mathieu Guindon
    Nov 9 at 18:09








3




3




Sounds like a job for a relational database.
– Comintern
Nov 9 at 17:47




Sounds like a job for a relational database.
– Comintern
Nov 9 at 17:47












Is there any sort of workaround?
– user7735684
Nov 9 at 18:02




Is there any sort of workaround?
– user7735684
Nov 9 at 18:02




4




4




If you're trying to create a relational database in something that isn't a relational database, everything will be a workaround.
– Comintern
Nov 9 at 18:03




If you're trying to create a relational database in something that isn't a relational database, everything will be a workaround.
– Comintern
Nov 9 at 18:03




1




1




sure there is
– Mathieu Guindon
Nov 9 at 18:09




sure there is
– Mathieu Guindon
Nov 9 at 18:09












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Use COUNTIF() to do the numbering:



=IF(E17="","",E17 & "-000-"& TEXT(COUNTIF($A$1:A16,E17&"-*")+1,"000"))


enter image description here






share|improve this answer



















  • 1




    Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
    – usmanhaq
    Nov 9 at 17:51






  • 2




    @user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
    – Mathieu Guindon
    Nov 9 at 17:58






  • 1




    @user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
    – Scott Craner
    Nov 9 at 18:07






  • 1




    @ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
    – user7735684
    Nov 9 at 18:11






  • 4




    @user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
    – Mathieu Guindon
    Nov 9 at 18:17













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230660%2fauto-increment-if-column-already-contains-a-certain-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Use COUNTIF() to do the numbering:



=IF(E17="","",E17 & "-000-"& TEXT(COUNTIF($A$1:A16,E17&"-*")+1,"000"))


enter image description here






share|improve this answer



















  • 1




    Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
    – usmanhaq
    Nov 9 at 17:51






  • 2




    @user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
    – Mathieu Guindon
    Nov 9 at 17:58






  • 1




    @user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
    – Scott Craner
    Nov 9 at 18:07






  • 1




    @ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
    – user7735684
    Nov 9 at 18:11






  • 4




    @user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
    – Mathieu Guindon
    Nov 9 at 18:17

















up vote
1
down vote



accepted










Use COUNTIF() to do the numbering:



=IF(E17="","",E17 & "-000-"& TEXT(COUNTIF($A$1:A16,E17&"-*")+1,"000"))


enter image description here






share|improve this answer



















  • 1




    Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
    – usmanhaq
    Nov 9 at 17:51






  • 2




    @user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
    – Mathieu Guindon
    Nov 9 at 17:58






  • 1




    @user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
    – Scott Craner
    Nov 9 at 18:07






  • 1




    @ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
    – user7735684
    Nov 9 at 18:11






  • 4




    @user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
    – Mathieu Guindon
    Nov 9 at 18:17















up vote
1
down vote



accepted







up vote
1
down vote



accepted






Use COUNTIF() to do the numbering:



=IF(E17="","",E17 & "-000-"& TEXT(COUNTIF($A$1:A16,E17&"-*")+1,"000"))


enter image description here






share|improve this answer














Use COUNTIF() to do the numbering:



=IF(E17="","",E17 & "-000-"& TEXT(COUNTIF($A$1:A16,E17&"-*")+1,"000"))


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 18:05

























answered Nov 9 at 17:34









Scott Craner

86.8k82449




86.8k82449








  • 1




    Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
    – usmanhaq
    Nov 9 at 17:51






  • 2




    @user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
    – Mathieu Guindon
    Nov 9 at 17:58






  • 1




    @user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
    – Scott Craner
    Nov 9 at 18:07






  • 1




    @ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
    – user7735684
    Nov 9 at 18:11






  • 4




    @user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
    – Mathieu Guindon
    Nov 9 at 18:17
















  • 1




    Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
    – usmanhaq
    Nov 9 at 17:51






  • 2




    @user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
    – Mathieu Guindon
    Nov 9 at 17:58






  • 1




    @user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
    – Scott Craner
    Nov 9 at 18:07






  • 1




    @ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
    – user7735684
    Nov 9 at 18:11






  • 4




    @user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
    – Mathieu Guindon
    Nov 9 at 18:17










1




1




Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
– usmanhaq
Nov 9 at 17:51




Kindly remember that use of such formula can lead to future errors if used for IDs, instead create one static id column for id as value and one for this formula, when you get a new id, paste it as value in the static id column, this will help you in future, because one wrong entry can update all the ids of all your rows and any linked formulae with ids will be messed up
– usmanhaq
Nov 9 at 17:51




2




2




@user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
– Mathieu Guindon
Nov 9 at 17:58




@user7735684 Excel isn't made for this. Using Excel as a relational database is a doomed endeavor.
– Mathieu Guindon
Nov 9 at 17:58




1




1




@user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
– Scott Craner
Nov 9 at 18:07




@user7735684 see edit, but take to heart what the others are saying, moving to a relational database would be better. While Excel can do a lot of what a database can it is too easy for the user to mess it up.
– Scott Craner
Nov 9 at 18:07




1




1




@ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
– user7735684
Nov 9 at 18:11




@ScottCraner, thank you so much, and I will have that conversation to begin moving data over to a relational database. Now I know where Excel is limited, I can work to better educate others!
– user7735684
Nov 9 at 18:11




4




4




@user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
– Mathieu Guindon
Nov 9 at 18:17






@user7735684 the biggest problem with a computed ID is that it's mutable, so if you delete a row, IDs can change for existing records, and then anything that was using them for lookups will now be pulling the wrong record - and then you add/insert a new record and the IDs change again, and now everything is mangled beyond repair. Or a user comes in and sorts the data and mangles everything all over again. If you get IT's cooperation, have SQL Server set up. If you don't, have your data live in an Access database (which will easily handle immutable IDs) - not in Excel.
– Mathieu Guindon
Nov 9 at 18:17




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230660%2fauto-increment-if-column-already-contains-a-certain-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?