Welcome to the fracta.net forum!

Share your coding ideas or ask questions.

Question Multidimensional array problem

  • rumceisz
  • Topic Author
  • Visitor
  • Visitor
12 years 1 week ago #94 by rumceisz
Multidimensional array problem was created by rumceisz
Hi All,

I have the following problem: I made a form feed for my HR department colleagues. This excel contains a sheets which is a form for the new colleagues. When the HR colleague choose a postion and knock the button, the macro fill the form with data related to the chosen position.
But there is a part which I couldn't achieve: there are Tasks, Subtasks, Sub-Subtasks in most of the positions and I'd like to list these strucuture in the form like this (see attached xls Template sheet):
SubtaskX
Sub-SubtaskZ
description
Sub-SubtaskU
description
description
.....
SubtaskY
Sub-SubtaskP
desc..

I tried to use multidimensional array but it didn't work, I got error maybe I missed something.

Can you please suggest?
The most easy to understand is to see the attached excel file Template sheet!

+ question: I'd like to fill an array from a column but there are many redundant values. How can I make an array from the column with unique values? See sheet1!

Thanks in advance!

Best regards,
Rumi

Please Log in or Create an account to join the conversation.

More
12 years 1 week ago #95 by roller
I do not see the attachment, did you forget to include the .xls file? Note that .xls extension is not allowed as an attachment and you must put your Excel file in a Zip folder!!!

Anyhow before looking at your file and understanding the problem you might want to use the VBA Dictionary object. You have to add a reference to the Microsoft Scripting Runtime to have the Dictionary object available in your code.

The Dictionary is like an array or a collection on steroids with few more functions. Once you have the dictionary you can use the Exist method to check if the Key is already present so you don’t add it again. For example:

Dim dic as Dictionary
Set dic = New Dictionary
If Not dic.Exists(“someValue”) Then
dic.Add “someValue”, value
End If

The above code checks if you already created a dictionary with Key = someValue and if it is not present it then adds it to the Dictionary. The value can be a single value or a class (or a Type) that can hold multiple data items related to the Key someValue.
Attachments:

Please Log in or Create an account to join the conversation.

  • rumceisz
  • Topic Author
  • Visitor
  • Visitor
12 years 1 week ago #96 by rumceisz
Replied by rumceisz on topic Re: Multidimensional array problem
Hi Roller,

thanks for the info and sorry. I attached the file compressed.

Bets regards,
Rumi
Attachments:

Please Log in or Create an account to join the conversation.

More
12 years 1 week ago - 12 years 1 week ago #97 by roller
OK I see your file and your problem is pretty complicated but I see a possible solution. I will give you enough code to get you started and if my code makes sense you can add to it and finish it off.

What I have done is a subroutine that will list all the tasks in column A, the Subtask in column B, the SubSub in C and the Description in C in a grouped manner. I only tested it once but if you think it does the trick then you have to figure out the formatting to go in the Form sheet.

To use this code first open your Excel file that you attached to the topic, add a new sheet and call it test.

Then copy the below code to you module and run it. Once finished check the output on the test sheet. Let me know how it goes??
Code:
Sub a() Dim ar() ar = Array("Scope", "Responsibility", "Scope of authority", "Additional info", "KPI", "Key competency", "Connection", "Knowledge", "Task") short_position = Sheets("Form").Range("E4").Value subT = "" subSub = "" For i = 0 To 8 r = r + 1 Sheets("test").Cells(r, 1) = ar(i) For e = 2 To 2000 If InStr(1, Sheets("Requirements").Cells(e, 2), short_position) > 0 And Sheets("Requirements").Cells(e, 3) = ar(i) Then If subT <> Sheets("Requirements").Cells(e, 4) Then r = r + 1 Sheets("test").Cells(r, 2) = Sheets("Requirements").Cells(e, 4) subT = Sheets("Requirements").Cells(e, 4) End If If subSub <> Sheets("Requirements").Cells(e, 5) Then r = r + 1 Sheets("test").Cells(r, 3) = Sheets("Requirements").Cells(e, 5) subSub = Sheets("Requirements").Cells(e, 5) End If r = r + 1 Sheets("test").Cells(r, 4) = Sheets("Requirements").Cells(e, 1) End If Next e Next i
Last edit: 12 years 1 week ago by roller.

Please Log in or Create an account to join the conversation.

Time to create page: 0.455 seconds
Powered by Kunena Forum