Select dynamic data in 2 columns, and repeat macro to next sheet

T

Tasha

Can someone help me with a macro? I tried recording this, but the issue I am
having is that the data changes from sheet to sheet, and would change month
to month, so it won't always be the same.
I have about 15 sheets in my workbook, all set up with the same columns. I
am trying to select all cells with data in them in columns C and D, then will
run the rest of my macro I have already built. I just can't figure out what
to add to my macro that will select only cells in columns C & D with data in
them. What I want it to do, select all cells in columns C & D with data in
them, then my macro multiples the data in those cells times -1 to change the
debits and credits. I have everything else done but the selection. I will
run this macro on each sheet, so if you can help me figure out a way to run
the macro, then select the next sheet, run the macro, etc. to the end, that
would be great too! Otherwise I'm selecting each sheet, running the macro,
then proceeding to the next sheet.

Thanks in advance for any help you can give me!!
 
L

Luke M

Sub YourMacro()

For Each ws In Worksheets
Sheets(ws.Name).Activate

'Choose one of the following lines:

'Use this line if data is from a constant
Columns("C:D").SpecialCells(xlCellTypeConstants, 1).Select

'Use this line if data is from a formula
'Columns("C:D").SpecialCells(xlCellTypeFormulas, 1).Select

For Each cell In Selection
cell.Value = cell.Value * -1
Next cell

'Any other coding you want done on sheet
'would got here

Next

End Sub
 
T

Tasha

Worked like a charm, thank you so much Luke!!!

Luke M said:
Sub YourMacro()

For Each ws In Worksheets
Sheets(ws.Name).Activate

'Choose one of the following lines:

'Use this line if data is from a constant
Columns("C:D").SpecialCells(xlCellTypeConstants, 1).Select

'Use this line if data is from a formula
'Columns("C:D").SpecialCells(xlCellTypeFormulas, 1).Select

For Each cell In Selection
cell.Value = cell.Value * -1
Next cell

'Any other coding you want done on sheet
'would got here

Next

End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*
 

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