Forum Discussion
Create a new table selecting info from an existing table in Excel vba
- Dec 11, 2020
The major problem: you changed cmdCancel_Click to cmdCancel_Click3 and cmdOK_Click to cmdOK_Click3. That won't work: Click is the name of the event, you can't just change that.
Other problems: the headers are now in row 1 instead of row 2, and your column offsets for the context and activity were off by 1.
See the attached version.
- dfhidromodDec 10, 2020Copper Contributor
Dear Hans,
what a script! Thanks a lot!
However there are things I do not understand and I am having a hard time to reproduce the code on the real document.
In these lines:
<For r = 3 To m
For i = 1 To n
If v(r, 13) = arrSelected(i) Then>- Why did you choose 3 for r =3?
- and also, the v(r,13)= arrSelected(i), what does it mean? why 13?
- What do "A" and "B" stand for? because there is nothing in Columns A and B, so I am guessing it is not referring to the columns. But what is it then?
I know you've already helped immensly, and I am novice in this language, but would appreciate if you took the time to answer me again 🙂
Regards,
Déborah
- HansVogelaarDec 10, 2020MVP
- Because the data on Sheet1 start on row 3 (row 1 is hidden and row 2 contains headers).
- v is an array that contains the values of the cells in columns A to Y, row 1 to m (the last used row). v(r, 13) is the array element in row r and column 13. Column number 13 corresponds to column M, the Working Area column.
- A and B are the columns on the new sheet that are filled by the code.
- dfhidromodDec 11, 2020Copper Contributor
Okay thanks for the explanations!
And one more thing, in this line <w.Range("B" & t).Value = v(r, 4 + s)> what does the 4+ s stands for?
And at the end in this line: <w.Range("A1:B1" & t).Borders....etc> the A1 and B1 correspond to the new sheet too? I am having troubles identifying where you set that the code opens a new sheet for these variables.
Cheers!