Conditionally copy cell from one column to another VBA

I

Isis

I want to loop through a column row by row, (at least I think I need to
loop ?)and then conditionally copy the value of that cell to a different
column (but the same row) after a mathmatical operation (times -1, or plus
..3 etc) on the value.

How would I do that ?

Can I adapt it so that the column can be 'set' when running ?

Thanks for any input
 
D

Don Guillett Excel MVP

I want to loop through a column row by row, (at least I think I need to
loop ?)and then conditionally copy the value of that cell to a different
column (but the same row) after a mathmatical operation (times -1, or plus
.3 etc) on the value.

How would I do that ?

Can I adapt it so that the column can be 'set' when running ?

Thanks for any input

Hard to tell without seeing as your explanation is lacking
"If desired, send your file to dguillett @gmail.com I will only look
if:
1. You send a copy of this message on an inserted sheet
2. You give me the newsgroup and the subject line
3. You send a clear explanation of what you want
4. You send before/after examples and expected results."
 
I

Isis

Hard to tell without seeing as your explanation is lacking
"If desired, send your file to dguillett @gmail.com I will only look
if:
1. You send a copy of this message on an inserted sheet
2. You give me the newsgroup and the subject line
3. You send a clear explanation of what you want
4. You send before/after examples and expected results."

Thanks for the reply Don.

What I want to do is something like this;

Col1 Col2
1
2
3
4

Sheet as above - I want to run some code and end up with;

Col1 Col2
1 Untouched
-2 x * -1
-3 x * -1
4 Untouched


I dont mind too much if the values are also left in the first column but I
want the results placed in the empty cells of Col2.

Imagine, if you would - I have a load of sheets of data that contain 3
columns - 'payments IN' , 'payments Out' and a 'Balance' column.

All the figures in 'payments In' and 'payments Out' are positive decimal
amounts - I want to end up with just 2 columns, one containing positive
decimals from 'payments IN' and also negative decimals from 'payments Out'
and a 'Balance' column where I will show a running balance.

Hope this makes sense;

So in pseudo code;

Loop i# = B1 to B? 'Loop through every filled B cell
If cell.Value 'If the is a value in this cell
Ci# = (cell.Value * -1) 'Copy over to C Column (same Row) - negative
End If
End Loop


Hope that makes sense

Thanks
 
P

Pete_UK

Here's a manual procedure that you can quickly apply. If you turn the
macro recorder on while you do it, then you will have the basis of a
macro for next time you need to apply it.

Apply Autofilter to column 2. From the filter drop-down select Blanks.
In the top-most visible cell in column 2 begin to enter the formula:

=-

then click on the cell in column 1 on the same row. Then you can copy
this formula down to cover the amount of data in the visible cells.
Then you can select All in the filter, and finally copy column B and
Paste Special | Values to fix the values.

Hope this helps.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top