Add currency to selected columns

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have to add the currency format e.g. £1234.56 to those columns with Cost as part of the column headings in row 3. Once the row 3 has a word 'Cost' in the heading then the whole column from row 4 onwards will be in currency format as £1234.56. Start from column to the last unknown column.

I have done the code below but it doesn't work:

Code:
Sub convertCurrency()

Dim i As Long
Dim c As Long
Dim Lastrow As Long
Dim LastCol As Long
Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
LastCol = Range("A1").End(xlToRight)
For c = 2 To LastCol
If Cells(4, c).Value Like "*Cost*" Then
    Cells(i, c).NumberFormat = "£###0.00"
    
End If
Next c


End Sub

Please could anyone help?
 
The currency format is now gone, all are in number format, I wonder is it because of the wild card *Cost is missing?
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
How about
Code:
Sub convertCurrency()
   Dim c As Long
   Dim Lastrow As Long
   Dim LastCol As Long
   Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
   LastCol = Range("A3").End(xlToRight).Column
   For c = 2 To LastCol
      If LCase(Cells(3, c).Value) Like "*cost*" Then
          Range(Cells(4, c), Cells(Lastrow, c)).NumberFormat = "£###0.00"
      Else: Range(Cells(4, c), Cells(Lastrow, c)).NumberFormat = "###0.00"
      End If
   Next c
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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