Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Formula or script to manipulate data in a cell

Posted on 2010-11-26
5
Medium Priority
?
398 Views
Last Modified: 2013-11-05
Hello, I need a formula or script to run in an Excel worksheet that if cell is greater than 40 I need that cell to be 40 and another cell to equal the difference. Example, cell A1 is 45, I want cell A1 to be 40 and Cell B1 to be 5. Is there a way I can do that or do I have to put the value 45 in a different cell, then have a formula in the other 2 cells referencing the one cell 45? Thanks
0
Comment
Question by:ccrockett1027
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 34218460
Maybe this in the sheet module? Right-click the sheet tab, View Code and paste in. It is activated every time something in column A is changed,
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 Then
    If Target.Value > 40 Then
        Target.Offset(, 1) = Target - 40
        Target = 40
    End If
End If

End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:moon_blue69
ID: 34218461
Display 45 in A1 display 40 in B1 and display 5 in C1. Data is crossreferenced and its impossible without programming. If you want to program you can have the value of in a variable find the difference display difference in B1 and then round value in A1
0
 
LVL 13

Assisted Solution

by:gbanik
gbanik earned 500 total points
ID: 34218622
Kept the "45" in A1
Formula in B1
=IF(A1>40,40,A1)
Formula in C1
=IF(A1>40,A1-B1,0)

See if it works out for you. See attached file.
40diff.xlsx
0
 

Author Closing Comment

by:ccrockett1027
ID: 34219543
Thanks for all the help, Both of the solutions worked. I am not sure which on i am going to implement in my spread sheet.

StephenJR - how would you select a range of cells in stead of the whole colunm? ie D259 thru D273

Thanks Again!
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34219742
My pleasure.

Change line 3 accordingly, e.g.:

If Not Intersect(Target,Range("D259:D273")) Is Nothing Then

Open in new window

0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question