VBA Resize Array, 1 Column to 4 Columns - vba

So I copied some data into Excel, but unfortunately for me when I pasted the data the chart format sorta died, so I ended up with a 1 column full of data(Column A). Basically A1 is suppose to be Movie name, A2 is suppose to be in B1(Cost of movie), A3 is suppose to be in C1(How long is the movie), and A4 is suppose to be in D1(Sequel:yes/no). And A5 is suppose to be in A2, A6 in B2, A7 in C2, A8 in D2, A9 in A3, A10 in B3..etc.. Its suppose to be a chart with 4 columns, but everything ended up in column A. Anyone can help me write a VBA code to rewrite the first column back to 4 columns? Thanks in advance.

No need for VBA. In excel, use INDIRECT in the four columns
=indirect("A"&(row()-1)*4+1) | =indirect("A"&(row()-1)*4+2) | ...
=indirect("A"&(row()-1)*4+1) | =indirect("A"&(row()-1)*4+2) | ...
...

Related

how to copy values in a diagonal down a range using vba

I have a range of data in one column like so:
and I'm trying to copy each value after the one in "A1" and move it one column over and up one row, for example (A2 copied to B1, A3 copied to B2, A4 copied to B3 etc.) like so:
Is there a few lines of code that can do this successfully?
In B1:
=IF(ISBLANK(OFFSET($A1,COLUMN()-1,0)),"",OFFSET($A1,COLUMN()-1,0))
fill down and across
Alternate:
=IF(ROW(B1)>COUNTA($A:$A)-COLUMN(A1),"",INDEX($A:$A,COLUMN(B1)+ROW(B1)-1))

Using Regexp_substr to display specific text

I have a column called keys with data in this format:
qwert! B1 12345! B3 abcde! B4 fgh14777
stat! B3 3456! C0 224466! B2 bbmm
I'm trying to use regexp_substr to display only text that starts with B3 and end with a character before the next exclamation mark (!)
So my desired result would be this:
B3 abcde
B3 3456
B3 might be be on any position within the string and the length of the text might vary as well. Not every row contains B3.
Any help would be appreciated!
This is a pretty simple regular expression:
select regexp_substr('qwert! B1 12345! B3 abcde! B4 fgh14777', 'B3[^!]+', 1, 1)
from dual

For Excel VBA, If B2 value did not change then A2 will keep same, If B2 is changed then A2 will increase by one

I need a VBA for the whole column B and A says that
if Value of Cell B2 did not change then A2 value will be the same
if B2 value is changed then A2 value will increase by one
Use this formula.
Put your staring number in A1.
Put this in A2:
=IF(B2<>B1,A1+1,A1)
And copy down.

Nested 'For' cycle required

I have four cells in an Excel workbook:
A1
A2
A3
A4
A1 and A2 cells include starting values such as 5 and 7. A3 has an formula and evaluates a result using A1 and A2's values. A4 cell has a target value. An iterational operation continue up to A3 cell's value equal to A4's 0,0001 approximation. For each A1's differential increment A2 will change depending on its range.
Can anybody help me with VBA including nested 'For' cycles?
My sample workbook:
There is an add-in with excel that is built to do this, it's called the solver addin.
There's a good tutorial here that explains how it works.

How to find a Particular value in particular range

Here is a example of the sheets, in which I am trying to create a macro with vba.
In the first sheet, there is a value for NAME in D3, which is 25, it can change but number only.
In second sheet, there is table. Where b1,b2, b3, b4 till b13, are name(variable) values from 1 to 13(As in sheet d3, different value). In A1 to a13, there is serial no. from 1 to 13.
In third sheet, there is table.
Where b1,b2, b3, b4 till b13, are name(variale) values from 14 to 26(As in sheet d3, different value). In A1 to a13, there is serial no. from 1 to 13.
So, I want that the macro should check for sheet 1 d3 value in all worksheet, if found it will check for the serial no. against it, put the no. in E6 filed.
Sorry of I've misunderstood your question but it sounds like a vlookup might do the trick rather than the need to write VBA and use the Find method.
If you combine the second and third sheet, so that Column A contains the possible values for NAME in D3, and the Serial Number in Column B, like this.
NAME | Serial
-----|-------
1 | qwerty
2 | bob
... | ...
You can then use a LOOKUP query as follows in E6.
=VLOOKUP($D$6,Sheet2!A:B,2,FALSE)
Hope this helps.