why is this not formatting as expected

MAMIBUSSOL

Board Regular
Joined
Jun 2, 2011
Messages
95
What wrong with this code?

Code:
    Range("A3:A388").Select
    For A = 1 To 18
        ActiveCell.Offset(0, B + 2).NumberFormat = "$#,##0.00"
        ActiveCell.Offset(0, B + 4).NumberFormat = "$#,##0.00"
        B = B + 7
    Next A

it is changing the formating for the first cell in the list but it is not changing subsequent rows, I don't understand why not
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Can you explain which cells that you are trying to change?

Note that format of the OFFSET function is OFFSET(row,column).
So you code is changing column numbers, not row numbers.
(I don't know if that is your intention).
 
Upvote 0
I am formatting columns; or rather attempting to

bit of explaination

I have going across the worksheet 18 batches of 5 columns, each column title is as follows:

Date
Supplier
Total
Paid
VAT
blank
blank
Date
Supplier
Total
Paid
VAT
blank
blank

as a result I attempting to format each total column and each VAT column, because of this I would have thought that this code would work, explaination of what I believe this code does.
It selects the rows I need to format, then processes across each column and changes the format of columns C, E, J, L etc

Code:
    Range("A3:A388").Select    For A = 1 To 18        ActiveCell.Offset(0, B + 2).NumberFormat = "$#,##0.00"        ActiveCell.Offset(0, B + 4).NumberFormat = "$#,##0.00"        B = B + 7    Next A
</PRE>
 
Upvote 0
You are only formatting the ActiveCell.
Code:
Set rng =Range("A3:A388")
    For A =1 To 18
        rng.Offset(0, B + 2).NumberFormat = "$#,##0.00"
        rng.Offset(0, B + 4).NumberFormat = "$#,##0.00"
        B = B + 7
    Next A
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top