Create multiple columns on one sheet from 1 column on another with logic
Posted
by
user450252
on Stack Overflow
See other posts from Stack Overflow
or by user450252
Published on 2010-09-17T15:43:12Z
Indexed on
2012/09/03
3:38 UTC
Read the original article
Hit count: 157
I am new to VBA and I am struggling trying to make this work. I am in need of a macro that will process each cell\column on Sheet1
and put the results on Sheet2
. I'm sure this is pretty easy for those who are more advanced with VB code. It contains many columns..
Anytime we encounter a —
or an empty cell, we populate the cell with -999
(see the example on Sheet2
) on the first column, which contains "0-2"
. Then we create 2 new columns and populate them with 0
on the first column and 2
on second column (see example on Sheet2
). If a value is found on only one side, we then populate both sides with the same number.
As each column is being process in Sheet1 and
Sheet1:
A B
Column1 Column2
Title Title2
0–2 0–4
3 —
— 5
—
— —
10–23 11—29
And the results should look like this on Sheet2
Sheet2
A B C D
Column1 Column1 Column2 Column2
Title-A Title-B Title-A Title-B
0 2 0 4
3 3 -999 -999
-999 -999 5 5
-999 -999 -999 -999
—999 -999 -999 -999
10 23 11 29
© Stack Overflow or respective owner