How to multiply the values within the conditional formatting range?

sneakikaz

New Member
Joined
Jun 8, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
I have a big data excel file, there are many negative numbers. Now I want to highlight all the negative values and then multiply it with a specific number (for example 0.5). Could you kindly show me how to do it?
Thank you.
 
So the working range is column B downwards?

try:
VBA Code:
Option Explicit
Sub multifly()
Dim i&, k&, lr&, n, min As Double, max As Double, rng, arr(1 To 1000000, 1 To 2)
n = 0.5 ' the multifly factor
min = -25 'lower value
max = -15 'upper value
lr = Cells(Rows.Count, "B").End(xlUp).Row ' last row of column B
rng = Range("B1:B" & lr).Value
For i = 1 To lr
    arr(i, 1) = rng(i, 1)
    If rng(i, 1) > min And rng(i, 1) < max Then
        arr(i, 1) = rng(i, 1) * n: arr(i, 2) = "B" & i
    End If
Next
With Range("B1:B" & lr)
    .Interior.Color = xlNone
    .Value = arr
End With
For i = 1 To lr
    If arr(i, 2) <> "" Then Range(arr(i, 2)).Interior.Color = vbYellow
Next
End Sub
 
Upvote 0
Solution

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
So the working range is column B downwards?

try:
VBA Code:
Option Explicit
Sub multifly()
Dim i&, k&, lr&, n, min As Double, max As Double, rng, arr(1 To 1000000, 1 To 2)
n = 0.5 ' the multifly factor
min = -25 'lower value
max = -15 'upper value
lr = Cells(Rows.Count, "B").End(xlUp).Row ' last row of column B
rng = Range("B1:B" & lr).Value
For i = 1 To lr
    arr(i, 1) = rng(i, 1)
    If rng(i, 1) > min And rng(i, 1) < max Then
        arr(i, 1) = rng(i, 1) * n: arr(i, 2) = "B" & i
    End If
Next
With Range("B1:B" & lr)
    .Interior.Color = xlNone
    .Value = arr
End With
For i = 1 To lr
    If arr(i, 2) <> "" Then Range(arr(i, 2)).Interior.Color = vbYellow
Next
End Sub
Thank you so much, it works perfectly. Em cảm ơn nhiều lắm ạ.
 
Upvote 0
So the working range is column B downwards?

try:
VBA Code:
Option Explicit
Sub multifly()
Dim i&, k&, lr&, n, min As Double, max As Double, rng, arr(1 To 1000000, 1 To 2)
n = 0.5 ' the multifly factor
min = -25 'lower value
max = -15 'upper value
lr = Cells(Rows.Count, "B").End(xlUp).Row ' last row of column B
rng = Range("B1:B" & lr).Value
For i = 1 To lr
    arr(i, 1) = rng(i, 1)
    If rng(i, 1) > min And rng(i, 1) < max Then
        arr(i, 1) = rng(i, 1) * n: arr(i, 2) = "B" & i
    End If
Next
With Range("B1:B" & lr)
    .Interior.Color = xlNone
    .Value = arr
End With
For i = 1 To lr
    If arr(i, 2) <> "" Then Range(arr(i, 2)).Interior.Color = vbYellow
Next
End Sub
Dear bebo021999,
If now I want to multiply the data in multiple columns, such as columns B, D, F, H, J, L, N, etc. what changes should I make in your VBA code?
 

Attachments

  • multiple columns.png
    multiple columns.png
    132 KB · Views: 10
Upvote 0
With more data to input manually, could you attach a mini sheet? Its the best i you would add "before" and "after" data
 
Upvote 0
First, you helped me to multiply the values in columns B
 
Last edited:
Upvote 0
First, you helped me to multiply the values in column B like this with your code, in this situation, any value in the range from 0 to 1 will be doubled.
BeforeAfter
2400-7.046882400-7.04688
2400.04-8.896882400.04-8.89688
2400.08-11.11882400.08-11.1188
2400.12-13.86562400.12-13.8656
2400.16-17.66562400.16-17.6656
2400.2-22.87192400.2-22.8719
2400.24-31.44692400.24-31.4469
2400.28-45.60942400.28-45.6094
2400.32-58.60312400.32-58.6031
2400.36-51.12192400.36-51.1219
2400.4-10.58442400.4-10.5844
2400.440.809372400.441.61874
2400.48-1.546882400.48-1.54688
 
Upvote 0
With more data to input manually, could you attach a mini sheet? Its the best i you would add "before" and "after" data
Now can you please help me to multiply all the values from 0 to 10 for example (only the figures in the yellow columns) with 2?
046.65634000.289068000.4453112000.3671916000.312520000.296882400-7.0468828000.0406332000.37536000.14688
0.04110.883400.040.28906800.040.445311200.040.3751600.040.328132000.040.257812400.04-8.896882800.040.03753200.040.3753600.040.13437
0.0868.0391400.080.3125800.080.421881200.080.351561600.080.335942000.080.252400.08-11.11882800.080.021873200.080.343753600.080.10312
0.1224.0703400.120.28906800.120.406251200.120.351561600.120.351562000.120.289062400.12-13.86562800.120.006253200.120.353600.120.1
0.1615.2031400.160.28906800.160.390631200.160.367191600.160.328132000.160.31252400.16-17.66562800.16-0.006253200.160.3753600.160.09375
0.211.4531400.20.25781800.20.3751200.20.390631600.20.31252000.20.351562400.2-22.87192800.2-0.009373200.20.396873600.20.1
0.249.44531400.240.29688800.240.390631200.240.367191600.240.328132000.240.31252400.24-31.44692800.24-0.0253200.240.371883600.240.07187
 
Upvote 0
Try this:
VBA Code:
Option Explicit
Sub multifly()
Dim i&, j&, min As Double, max As Double, fact As Double, rng
min = 0 ' adjust to actual value
max = 10 ' adjust to actual value
fact = 2 ' adjust to actual value
rng = Cells(1).CurrentRegion.Value
For i = 1 To UBound(rng)
    For j = 2 To UBound(rng, 2) Step 2 ' loop through column B,D,F,H,...
        If rng(i, j) >= min And rng(i, j) <= max Then rng(i, j) = rng(i, j) * fact
    Next
Next
Cells(1).CurrentRegion.Value = rng
End Sub

BEFORE
Book1
ABCDEFGHIJKLMNOPQRST
1046.65634000.289068000.4453112000.3671916000.312520000.296882400-7.0468828000.0406332000.37536000.14688
20.04110.883400.040.28906800.040.445311200.040.3751600.040.328132000.040.257812400.04-8.896882800.040.03753200.040.3753600.040.13437
30.0868.0391400.080.3125800.080.421881200.080.351561600.080.335942000.080.252400.08-11.11882800.080.021873200.080.343753600.080.10312
40.1224.0703400.120.28906800.120.406251200.120.351561600.120.351562000.120.289062400.12-13.86562800.120.006253200.120.353600.120.1
50.1615.2031400.160.28906800.160.390631200.160.367191600.160.328132000.160.31252400.16-17.66562800.16-0.006253200.160.3753600.160.09375
60.211.4531400.20.25781800.20.3751200.20.390631600.20.31252000.20.351562400.2-22.87192800.2-0.009373200.20.396873600.20.1
70.249.44531400.240.29688800.240.390631200.240.367191600.240.328132000.240.31252400.24-31.44692800.24-0.0253200.240.371883600.240.07187
Sheet1


AFTER:
Book1
ABCDEFGHIJKLMNOPQRST
1046.65634000.578128000.8906212000.7343816000.62520000.593762400-7.0468828000.0812632000.7536000.29376
20.04110.883400.040.57812800.040.890621200.040.751600.040.656262000.040.515622400.04-8.896882800.040.0753200.040.753600.040.26874
30.0868.0391400.080.625800.080.843761200.080.703121600.080.671882000.080.52400.08-11.11882800.080.043743200.080.68753600.080.20624
40.1224.0703400.120.57812800.120.81251200.120.703121600.120.703122000.120.578122400.12-13.86562800.120.01253200.120.73600.120.2
50.1615.2031400.160.57812800.160.781261200.160.734381600.160.656262000.160.6252400.16-17.66562800.16-0.006253200.160.753600.160.1875
60.211.4531400.20.51562800.20.751200.20.781261600.20.6252000.20.703122400.2-22.87192800.2-0.009373200.20.793743600.20.2
70.2418.89062400.240.59376800.240.781261200.240.734381600.240.656262000.240.6252400.24-31.44692800.24-0.0253200.240.743763600.240.14374
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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