Having trouble selectively copying calculated values to a Column

cjpaul

New Member
Joined
May 30, 2011
Messages
5
Good day to all. I would like to get calculated fields to automatically update fields on the data entry page and am having trouble. I have a sheet (Sheet1) with Columns E, F, G which correspond to Height, Width and Depth in Feet. The range is E5:G105. I have corresponding Columns H, I and J which correspond to the same headings but in Meters.

I created a second Tab (Sheet2) where I copied the same 6 columns and use IF statements to calculate data based on information entered on Sheet1 for instance if they enter 1 in cell E5 I then calculate the Metric equivalent on Sheet2 in the corresponding Metric Column H. This all works wonderfully but i want to copy the missing data (either the English or Metric counterpart to what they entered) back to Sheet1 (the data entry sheet) and I am having a problem. Unfortunately, we can get a mixture of both metric and English measurements on the same project so it is not as simple as entering either all English or metric and copying the other back.

I would prefer to do this dynamically as they enter the data but could if I need to, use a single button for completing this task once all entry was finished.

Any help would be greatly appreciated.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Right-click on the Sheet1 tab and select View Code in the pop-up menu
Paste the code below in the VBA edit window.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.EnableEvents = False
    On Error GoTo ReEnable
    If Not Intersect(Range("E5:G105"), Target) Is Nothing Then
        ' Feet to Meters
        If IsNumeric(Target.Value) Then Target.Offset(, 3).Value = Target.Value * 0.3048
    ElseIf Not Intersect(Range("H5:J105"), Target) Is Nothing Then
        ' Meters to Feet
        If IsNumeric(Target.Value) Then Target.Offset(, -3).Value = Target.Value * 3.2808399
    End If
ReEnable:
    Application.EnableEvents = True
    
End Sub
 
Upvote 0
That is spectacular, thank you so much
This code worked perfectly and i would like to add columns K5:K105 (Volume by gallons) and L5:L105 (Volume by Liters) to the dynamic calculations. I have tried to add the additional code to reflect this but it does not calculate when one or the other data is entered in either column. here is what i did:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ReEnable
If Not Intersect(Range("E5:G105"), Target) Is Nothing Then
' Feet to Meters
If IsNumeric(Target.Value) Then Target.Offset(, 3).Value = Target.Value * 0.3048
ElseIf Not Intersect(Range("H5:J105"), Target) Is Nothing Then
' Meters to Feet
If IsNumeric(Target.Value) Then Target.Offset(, -3).Value = Target.Value * 3.2808399
End If
If Not Intersect(Range("K5:K105"), Target) Is Nothing Then
' Gallons to Liters
If IsNumeric(Target.Value) Then Target.Offset(, 1).Value = Target.Value * 3.7854
ElseIf Not Intersect(Range("L5:L105"), Target) Is Nothing Then
' Liters to Gallons
If IsNumeric(Target.Value) Then Target.Offset(, -1).Value = Target.Value / 3.7854
ReEnable:
Application.EnableEvents = True

End Sub

once again any help would be greatly appreciated
 
Upvote 0
This code worked perfectly and i would like to add columns K5:K105 (Volume by gallons) and L5:L105 (Volume by Liters) to the dynamic calculations. I have tried to add the additional code to reflect this but it does not calculate when one or the other data is entered in either column. here is what i did:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ReEnable
If Not Intersect(Range("E5:G105"), Target) Is Nothing Then
' Feet to Meters
If IsNumeric(Target.Value) Then Target.Offset(, 3).Value = Target.Value * 0.3048
ElseIf Not Intersect(Range("H5:J105"), Target) Is Nothing Then
' Meters to Feet
If IsNumeric(Target.Value) Then Target.Offset(, -3).Value = Target.Value * 3.2808399
End If
If Not Intersect(Range("K5:K105"), Target) Is Nothing Then
' Gallons to Liters
If IsNumeric(Target.Value) Then Target.Offset(, 1).Value = Target.Value * 3.7854
ElseIf Not Intersect(Range("L5:L105"), Target) Is Nothing Then
' Liters to Gallons
If IsNumeric(Target.Value) Then Target.Offset(, -1).Value = Target.Value / 3.7854
ReEnable:
Application.EnableEvents = True

End Sub

once again any help would be greatly appreciated
Sorry, i also added End If
End If before End Sub
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.EnableEvents = False
    On Error GoTo ReEnable
    
    If IsNumeric(Target.Value) Then
        If Not Intersect(Range("E5:G105"), Target) Is Nothing Then
            ' Feet to Meters
            Target.Offset(, 3).Value = Target.Value * 0.3048
        ElseIf Not Intersect(Range("H5:J105"), Target) Is Nothing Then
            ' Meters to Feet
            Target.Offset(, -3).Value = Target.Value * 3.2808399
        ElseIf Not Intersect(Range("K5:K105"), Target) Is Nothing Then
            ' Gallons to Liters
            Target.Offset(, 1).Value = Target.Value * 3.7854
        ElseIf Not Intersect(Range("L5:L105"), Target) Is Nothing Then
            ' Liters to Gallons
           Target.Offset(, -1).Value = Target.Value / 3.7854
        End If
    End If
    
ReEnable:
    Application.EnableEvents = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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