Special Cells Constants

finspa

New Member
Joined
Jan 15, 2015
Messages
42
Hi all

I have a question about special cells.

I am using Selection.SpecialCells(xlCellTypeConstants, 1).Select to copy / paste special - multiply to switch between GB£ and US$ in a large worksheet.

The problem is, the code is altering dates and percentages that should stay erm, constant.

Is there a way to tell the function to only look at certain fields, i.e. to ignore the dates and percentages?

My guess is that isn't easy as there is no real way to tell the difference between a number and a percentage value, so plan b would be to specify the columns that need updating. Is there an easy way to combine xlcelltyoeconstants and specified columns only, bearing in mind they are not necessarily next to each other. Example (cols B:P, U:V, AD:AJ, AL).select

Many thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi finspa,

If you are able to specify the columns, then your plan b could be done like this...
Code:
 With ActiveSheet
   Set rMyColumns = .Range("B:P,U:V,AD:AJ,AL:AL")
   Set rConstants = rMyColumns.SpecialCells(xlCellTypeConstants, 1)
 End With
 
 If Not rConstants Is Nothing Then
    '....your code continues

If the specific columns or ranges can't be identified at design time, an alternative would be to step through each cell of the range returned by SpecialCells, and only process those cells that have a NumberFormat property that doesn't end in "%". If you chose this option, it might be simpler to have VBA do the math on those cells instead of trying to do PasteSpecial with Multiply on this subset of your selection.
 
Last edited:
Upvote 0
Hi finspa,

If you are able to specify the columns, then your plan b could be done like this...
Code:
 With ActiveSheet
   Set rMyColumns = .Range("B:P,U:V,AD:AJ,AL:AL")
   Set rConstants = rMyColumns.SpecialCells(xlCellTypeConstants, 1)
 End With
 
 If Not rConstants Is Nothing Then
    '....your code continues

If the specific columns or ranges can't be identified at design time, an alternative would be to step through each cell of the range returned by SpecialCells, and only process those cells that have a NumberFormat property that doesn't end in "%". If you chose this option, it might be simpler to have VBA do the math on those cells instead of trying to do PasteSpecial with Multiply on this subset of your selection.

Many thanks Jerry
Sorry for being a bit dumb but how would that fit with my code..

Code:
Application.Goto Reference:="Rate"
 Selection.Copy
 Selection.SpecialCells(xlCellTypeConstants, 1).Select
 Selection.PasteSpecial Paste:=xlValues, Operation:=xlDivide, SkipBlanks:= _
 False, Transpose:=False
 End Sub
 
Upvote 0
Here's some code you can try...

Code:
Sub ConvertConstants()

 Dim rConstants As Range, rMyColumns As Range
   
 With ActiveSheet
   Set rMyColumns = .Range("B:P,U:V,AD:AJ,AL:AL")
   Set rConstants = rMyColumns.SpecialCells(xlCellTypeConstants, 1)
 End With
 
 If Not rConstants Is Nothing Then
   Application.Goto Reference:="Rate"
   Selection.Copy
   rConstants.PasteSpecial Paste:=xlValues, Operation:=xlDivide, _
      SkipBlanks:=False, Transpose:=False
 End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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