• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Regarding VBA codes, stucked . Need help

Ajinkya

Member
Dear Masters,


First of all i would like to thanks for your valuable guidance, because of ur direction i could able to learn new things.


Also im very basic learner of excel VBA programming.


With your guidance, i have prepared template based on VBA codes.


Require ur more guidance, i have been stucked into something, please help...


1. i'm not able to link models with its brand, require codes for the same.


e.g if i am selecting "Honda" brand, models should appaer in dropdown box as CRV, City etc....


and if i am selecting " Tata Motors" models should appear in dropdown box as Nano, Safari, Indica etc...


2. I wants in "Update Production Plan" and "Update Actual Production", all details are compulsary like without Brand, Model, Qnty and Date data should not update or save, it should give error msg like (Please update all mandetory details)


Masters, template (Switch On - Data Entry V7.1) is shared on following link, please help.


https://hotfile.com/dl/162774237/c669383/Switch_On_-_Data_Entry_V7.1.xlsm.html


that you know it will help me to learn new intresting things.


Thanks in advance.


"Brand and its models are taken just for example, and these are taken just for testing and for more convenience purpose only"
 
Hi Ajinkya ,


Can you check out your file here ?


https://docs.google.com/open?id=0B0KMpuzr3MTVZkVCWUN5MEpyems


Download the file , and see the changes I have made ; I have made them only for the Plan Update ; I am sure you can follow the same principles to make the changes for the Actual Production Update also.


The changes have been made to take care of your first point only.


Narayan
 
Hi Narayan,


First thanks to teach me, i have done required changes also added some models


but i am not able to add more brands in dropdown list (like Mercedes Benz, BMW, Wolksvagon etc.)


The file "Switch On - Data Entry V7.2 (Solved)" is uploaded on...

https://hotfile.com/dl/162812618/e8158a6/Switch_On_-_Data_Entry_V7.2_(Solved).xlsm.html


Please help also please suggest for my earlier point number 2.

{ Point 2. I wants in "Update Production Plan" and "Update Actual Production", all details are compulsary like without Brand, Model, Qnty and Date data should not update or save, it should give error msg like (Please update all mandetory details)}
 
Hi Ajinkya ,


The following are the significant statements in the code :


1.

[pre]
Code:
ComboBox1.List() = Application.WorksheetFunction.Transpose(ThisWorkbook.Worksheets("Sheet1").Range("B3:C3").Value)
Here the car manufacturers are listed in the cells B3 and C3 ; the list of car manufacturers extends across the 3rd row , over several columns. If you wish to add more manufacturers , then you need to have their names in D3 , E3 , F3 and so on. Thereafter , change the address reference in the above statement to reflect the additional entries. Also , as each manufacturer is added , create a range name referring to that particular manufacturer. If you see , I have already added Honda and Tata_Motors. You will need to do the same for Mercedes_Benz , BMW , Volkswagen and so on.


2.

selected_text = Application.WorksheetFunction.Substitute(ComboBox1.Value, " ", "_")
ComboBox2.List() = Range(selected_text).Value
[/pre]
When you add more models , these will listed in the rows B4 , B5 , B6 and so , if they pertain to the manufacturer Honda ; more models from the Tata Motors stable will appear in column C , and so on.


Once you do the above , the names will automatically appear in the drop-downs.


Narayan
 
Hi Narayan,


If im extenidng manufacture range, getting debug error.


and it is gets highlight yellow color on "ComboBox2.List() = Range(selected_text).Value" statement...
 
Hi Ajinkya ,


Have you extended the range , the way it has been explained in my earlier post ?


Can you post the range you have used to add the manufacturers ?


Have you added the range names corresponding to the manufacturers ?


Please go through my earlier post , and see if you have complied with all the requirements mentioned there.


Narayan
 
Hi Narayan,


As per my privious blog, I have extended manuf actures in D3=Mercedes, E3=BMW and F3= Wolksvagon and as per following made changes in the statement (instead of C3, made F3)


Public Sub UserForm_Initialize()

ComboBox1.List() = Application.WorksheetFunction.Transpose(ThisWorkbook.Worksheets("Sheet1").Range("B3:F3").Value)

End Sub


When im going back to check the changes, in dropbox existing and new added manufactures are appearing but if im selecting new one getting debug error and if im click in debug its goes on the following statement

ComboBox2.List() = Range(selected_text).Value


and making it yellow highlight.


PDN
 
Hi Ajinkya,


I am addressing you point number 2 where you need to stop user if they do not fill the required fields. I am doing this for "Update Material Plan" form(You can replicate the same in other form). Double click on "Update" button of this form and paste the following code just above the piece of code you have written:


'if user do not select brand

If Me.ComboBox1.Value = "" Then

MsgBox "Please select brand from drop down list.", vbExclamation, "Update Material Plan"

Me.ComboBox1.SetFocus

Exit Sub

End If


'if user do not select Model

If Me.ComboBox2.Value = "" Then

MsgBox "Please select Model from drop down list.", vbExclamation, "Update Material Plan"

Me.ComboBox2.SetFocus

Exit Sub

End If


'if user do not enter Material Plan Quantity

If Me.TextBox1.Value = "" Then

MsgBox "Please enter Material Plan Quantity.", vbExclamation, "Update Material Plan"

Me.TextBox1.SetFocus

Exit Sub

End If


if user do not fill any one of the required field and hit the "update" button, he/she will get an message to fill that particular field and will be stopped in going forward.


Suggestion:


However, I would suggest you to create a textbox in the userform just beside the calender button to hold the selected date from the calender, and then write a similar code like this to check if user selects the date or not:


'if user do not select date

If Me.TextBox2.Value = "" Then

MsgBox "Please select date.", vbExclamation, "Update Material Plan"

Me.TextBox2.SetFocus

Exit Sub

End If


Let me know if you need any further help regarding this..


Regards,

Kaushik
 
Hi Kaushik,


thanks a lot its working, if the brand, model, qnty is null....


but as you suggested for date, :-(

not able get it done ,


pls guide


also pls help in to my point no. 1, as i want to add more manufactures but its getting debug error....
 
Hi Ajinkya,


Happy to hear that it is working for you.


Regarding the calender stuff, may I request you to share your e-mail ID with me? It will be easier for me share the final product (spreadsheet with code) with you with the required work done.


Regards,

Kaushik
 
Hi Ajinkya ,


Let me explain with more details.


1. The first combobox , which displays the manufacturers' names , is an absolute range reference , since the manufacturers' names are in just one row , whose reference is known beforehand.


2. The second combobox , which displays the models pertaining to the selected manufacturer , cannot be treated in the same way. If Honda is selected , then the models need to be taken from column B , if Tata Motors is selected , then the models need to be taken from column C ; in case you add more manufacturers , the models will have to come from columns D , E and so on.


3. There is more than one way to get the correct list of models into the second combobox ; the method I have chosen , depends on defining named ranges , which refer to the respective car manufacturers' models. Thus , I have defined a named range called Honda , which refers to :


=Sheet1!$B$4:INDEX(Sheet1!$B:$B,COUNTA(Sheet1!$B:$B)+2)


Similarly , the range Tata_Motors refers to :


=Sheet1!$C$4:INDEX(Sheet1!$C:$C,COUNTA(Sheet1!$C:$C)+2)


The +2 is because the first two rows in columns B and C are blank.


Now , a range name cannot have spaces in it i.e. you cannot have a range name such as Tata Motors ; it can be Tata_Motors. When you select a car manufacturer , suppose you select Tata Motors ; the space character will have to be replaced by the underscore "_" ; this is the reason for the following statement :


selected_text = Application.WorksheetFunction.Substitute(ComboBox1.Value, " ", "_")


Since , you are getting an error in the selection of the second combobox , please once more confirm that you have defined the additional named ranges such as Mercedes_Benz , BMW , Volkswagen and so on , referring to their respective columns using the formulae given above for the ranges Honda and Tata_Motors.


Narayan
 
Hi Narayan,


Could you pls suggest me in following statement.


Public Sub UserForm_Initialize()

ComboBox1.List() = Application.WorksheetFunction.Transpose(ThisWorkbook.Worksheets("Sheet1").Range("B3:F3").Value)

End Sub


Private Sub ComboBox1_Change()

selected_text = Application.WorksheetFunction.Substitute(ComboBox1.Value, " ", "_")

ComboBox2.List() = Range(selected_text).Value

End Sub


Thanks ;-)
 
Hi Ajinkya ,


I am sorry I cannot explain any more clearly. Please take up this point with Kaushik ; I am sure he will help you out.


Narayan
 
Okie Narayan,

thanks for your efforts, may im not able to catch it ;-(

but once day will be able to.... :)


@ Koushik, pls help...
 
Dear Ajinkya,


I have made some changes in your "Update Material Plan" form and accomodate the textbox along with calender which I was talking about in my last post.


Wherever I have made changes/ additions in the code, I have marked those places with 'My code comment. Hence you can search all the changes by searching with the key word 'My code in the entire project.


I have sent you the file to your aforementioned e-mail ID. Let me know if you face any challenge regarding this.


Regarding your point number 1, I believe Narayan has answered that very well, explained it very clearly. However, I will try to answer it in a little different way, if I can, sometimes tomorrow. Would that be fine to you dear?


Regards,

Kaushik
 
Hi Koushik,


thanks i had received your mail also meanwhile i have gone through it.


there is small query, if i'm selecting date from calender 10-July-2012 then in the txtStartDate (date text box, which you have added) it is showing Oct-7-2012.


I have tried to change date format and also have tested so many ways but same thing is happening, date selection is correct but showing and updating wrong date.


Pls check and do the needful.
 
Ajinkya,


It is working fine for.


If I select 5th July 2012 form calender, it gets stored in the textbox as 5-Jul-2012 and getting entered in the same format in the "Data" sheet at column "E".


I have sent you an e-mail with the screenshot attached in the word for your reference. Please check your e-mail for the same.


Regards,


Kaushik
 
Hi Koushik,


your snapshot is correct, let me check date setting at my end.


Could you pls guide me about my earlier pt. no. 1, i know narayan has explained me as his best but im very basic learner of VBA....pls help me.


i want to add 5 or 6 manufactures and each max 40 models in dropdown box.


thanks ;-)
 
Hi Narayan,


I got that....your detailed description is very helpful me, your effort are not wasted.


After such a deep analysis, I have done it from my end,

if im not wrong there is some logic of Name Manager....from defined name...


@ Koushik, also thanks for your guidance.


Narayan & Koushik, really about coding.... my interest level is increased.... with such type of your helpful guidance.


Thanks once again :)))))
 
Hi Ajinkya,


As promised, I have emailed you the work. Please check your email for the same.


Description of the work:


Consider:

AA,BB,CC,EE,DD,EE,FF are your brands (placed at Shhet1 from row 12 to 17)


Brands are aligned with models and placed in sheet1 from B13 to G19


Identified the last row of each column (A to G)


Fill combobox1 under userform_initialize event


Run the loop for each match (Brand to Model) to update combobox2 within IF....THEN.....END IF statement


Hope this helps.


Regards,

Kaushik
 
then always blanket curtains.
Westerners and Midwesterners aspiration cost an average of $774 and $696 respectively It can attach to your shoes before you walk into your home.In the Laundry suite have a three hamper system that you can separate your loads ahead laundering. The truth is - washing is hard work - and have to be done properly plus cautiously It's not about wiping some crumbs off a counter. Depending on what you are using your garment steamer for.These alter types of cleaners are affable among a variety of differentmerely never everyone can run a affair with the quality that you would anticipate so tell sure that the cleaning company can back up their demands of experience reducing back strains caused by hard scrubbing a company in the Philippines principally focused aboard back-end SEO and Operational advocate apt medium sized businesses.perspective BullionUK's quality selection of gold here: http://www Several landlords indicate that it namely important to clean the brushes afterward each use for they collect hair and blanket fibres. Another issue maA machine undergoes clothes and mow and thus needs maintenance Of kernel namely for it to have an skillful alternatively someone specialized in this field fix the machine If it namely not properly tight it can occasion quite wrong effects If you absence to cut on unnecessary expenses such as repairing marred portions deserving to misdemeanor and likewise labor paid apt experts for of this thing every month it is important to employment specialized peopleThe advantage of having this person is for he ambition be learned to inform you on different types and which types apt go for He want be of kernel meantime he comes apt servicing itProduction of such elements never ceases One has been released namely can handle substances namely can be raised according blaze accessible A comely instance is titanium It aspiration be very important among such factoriesin preventing flame alternatively explosions In line with cle.
 
Back
Top