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.
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!
The line
Set w = Worksheets.Add(After:=Worksheets(Worksheets.Count))
creates a new worksheet and assigns it to the variable w, so in the rest of the code, we can use w to refer to the new sheet.
The variable s contains a number representing the selected language: 1 for Portuguese, 2 for English etc.
I see now that 4 + s should have been 3 + s. This is the column number containing the titles in that language: column 4 (D) for Portuguese, 5 (E) for English etc.
I will attach a corrected workbook.
In w.Range("A1:B" & t).Borders, w is the new sheet, so this line refers to columns A and B on the new sheet.
- dfhidromodDec 11, 2020Copper Contributor
Okay! Starting to understand better! This code is really impressive and cool.
I tried it on my new worksheet (because I had to add things) (and adapting the code to it), but when I select the languages, nothing happens. I don't even get an error message. There is just nothing.
In the file attached to this message, there are the headers I am using and their positions in the worksheet. I thought I changed everything I needed to make it work, but does not seem to give me results.
Do you think you could have a look at the changes I made to your code and identify what I've missed?
I marked all the changes in green with this " ' "
Cheers!
- HansVogelaarDec 11, 2020MVP
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 18, 2020Copper Contributor
okay, I see! thanks for the explanation!
Another last thing, do you know how to define the width of the 2nd column in the new sheet created?
Because, i get super wide columns and the text does not fit in it.
Attached, there is a picture illustrating better what I'm trying to explain.
All the best,
Déborah