Macro to convert rows with tonnes inputs to kilograms

lekh0602

New Member
Joined
Jul 9, 2014
Messages
33
Hi,

I have specific columns where I input values manually - the rows are constant so always from B11 to Q38 and down to row 72 (B-Q). The inputs are values in tonnes that I would like to convert to kilograms by adding three 0. However, some of the cells are also text cells which should not have the three 0s added. Will it be possible to create a macro that auto fill every number cell with "000" but not to any text cell?

Any assistance in this matter is highly appreciated.

Thanks! :)
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You don't need a macro.

Enter 1000 in an empty cell and copy it.

Select the data, Edit > Paste Special, tick Multiply and click OK.

Text cells will be ignored.
 
Upvote 0
Thanks, VoG

Since all cells will be filled with values in tonnes I would like just one button to convert from tonnes to kilograms, since the people using the sheet are not very Excel savvy. That's why I would like to minimise the number of actions they need to do.

Do you think a macro will be able to do that?
 
Upvote 0
Try

Code:
Sub Tonnes()
With Range("IV1")
    .Value = 1000
    .Copy
End With
Range("B11:Q72").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
End Sub
 
Upvote 0
Thank you very much, VoG - I just tried to insert the code like this:

Sub FoecastDI_Button1_Click()


Sub Tonnes()
With Range("IV1")
.Value = 1000
.Copy
End With
Range("B11:Q72").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply


End Sub

BUT I get a "Compile error: Expected End Sub"?
 
Upvote 0
Try

Code:
Sub FoecastDI_Button1_Click()
With Range("IV1")
    .Value = 1000
    .Copy
End With
Range("B11:Q72").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
End Sub
 
Upvote 0
I would probably add this line of code between the end with and Range("B11.......
Code:
    Range("B11:Q72").Select
    Selection.SpecialCells(xlCellTypeConstants, 1).Select
which only selects the numbers
 
Upvote 0
THANKS! That works now but can it multiply only the cells where the values have been changed? Otherwise it keeps multiplying with a 1000 to all cells increasing the sum too much.
 
Upvote 0
Right click the sheet tab and select View Code then paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target, Range("B11:Q72")) Is Nothing Then
    Application.EnableEvents = False
    For Each c In Target
        If IsNumeric(c.Value) Then c.Value = c.Value * 1000
    Next c
    Application.EnableEvents = True
End If
End Sub

Values will be converted as they are entered.
 
Upvote 0
Thanks a lot, VoG - that works perfectly.

Can I insert the same rode to another range but in the same worksheet? I have two tables in one sheet and one range is B11:Q72 and the other is B11:Q30?
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,830
Members
449,190
Latest member
rscraig11

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