Overwriting Formula With A Value But Still Keep Formula If Value Is Deleted
Mar 25, 2012
I would like to use the code below such that column "A" contains unit list pricing, Column "B" calculates the discount from the net pricing in Column "C." For example, A1 = 100, B1 = 1- (C1/A1), and C1 by default is equal to A1 but if the user enters in a net rate, say 85 in C1, it retains the 85 in C1 but if then later deleted, the C1 automatically reverts back to =A1. The code below works great for C1 but for the life of me, I cannot figure out how to modify the code and have it work correctly for a range of cells in Column "C" or all of Column "C."
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Address(False, False) = "C1" Then
If IsEmpty(.Value) Then
Application.EnableEvents = False
.Formula = "=A1"
Application.EnableEvents = True
End If
End If
End With
End Sub
I have a spreadsheet that has a formula placed from cells B21 through to AT21. This formula is present in the sheet 95% of the time, but occassionally the user has to enter his/her own value in one of the cells.
How can I check or the user be reminded that he/she has deleted a formula and replaced it with a user defined value. ie a message box(only as a warning) to be displayed just before the workbook is printed. The user should be able to acknowledge the message displayed and carry on.
I'm not sure if this is impossible (surely not) or if I'm just Googling the wrong terms (most likely). I have a sheet that we use to record staff shifts and when they take their lunch breaks. By default most of our employees have a 1 hour lunch and they take it 4 hours after they start. So far so good, I've set up a formula to work out what time their lunch would start and end based on this.
N237: =IF(AND(L237>0,L237<>"NWD"),SUM(L237+(1/6)),0) - Lunch start 4 hours after start time in L237 (NWD = Non working day) M237: =IF(N237>0,SUM(N237+(1/24)),0) - Lunch ends 1 hour after lunch start time in N237
However, not everybody follows the default - some people take lunch later, or don't take as long due to working shorter hours.
What I'd like to do is allow users of the sheet to overtype the times generated by the formulas when applicable, but if they delete their own custom value for lunch breaks I would like the formulas to re-appear and thereby return lunch times to the default values.
I could do this through VBA with a button to look for blank cells, but I would prefer it to happen automatically. Is this possible and if so what code would I need to make the magic happen?
I should maybe have mentioned that this sheet has space for 250 names and an area for each day of the week, so these formulas would appear in 1,250 different places
I am using following code to effect a change which works fine:
Code: Private Sub Worksheet_Change(ByVal Target As Range) Sheets("Closed Flts").Unprotect "abcd" Sheets("Faults").Unprotect "abcd"
[Code].....
But when the sheet is unprotected to effect this change the formula in cells ( row I and L) are visible to user and can delete them. Or they can even delete the cell itself or modify formula.
The formule in Row I is Code: =IF(A12="","",IF(G12=1,A12,IF(G12=2,A12,IF(G12=3,A12+1,IF(G12=4,A12+5,IF(G12=5,A12+28,"priority?")))))) And in Row L is Code: =IF(A13="","",IF(I13
We have created a macro that basically looks for rows that contain an "H" and hides the row if it does.
Users can add new rows throughtout the year to this spreadsheet. and based on certain criteria, an H or U will be placed in a hidden column which the macro looks at and hides any row it finds an H.
The user has to click on the button that has the macro assigned to it once they have finished working on the spreadsheet.
The problem we're finding is that for users who insert/delete rows, once they click the button it takes up to 15 seconds to run through macro (which is ok). However, users who haven't added or deleted any rows and who click the button, they have to wait upto 5 minutes (which isn't ok) for the macro ro run.
We can't figure out why the macro takes longer to run when no changes have been made?
cell A3 contains a drop down list of student names.
say, William is the 1st student listed on cell A1.
when William is selected his math grade shows up on cell B3 & his English grade on cell C3
I figured out how to make cells B3 & C3 change according to selected student from cell A3. All data comes from the Database Table, which is locked/unedittable.
I have a worksheet containing employee information (i.e. name, manager, department, etc.). I also have a userform that will be used to make changes to the employee information. The userform has three comboboxes and, when activated, the userform is populated with the existing data in the worksheet.
Here is the problem - I need to have the existing worksheet data populate (as it does now) but also have the combobox choices available in the event that one of the 'combo' fields need to be changed. How do I keep the existing worksheet data AND keep the functionality of the combobox?
I need to create a macro that will insert copied cells(cell range) from the clipboard into a cell on a different workbook and "shift cells down". The cell range in the clipboard will always be different and the position of the cell I select to insert the data into will also vary.
I have a large spreadsheet which I have extracted the data I need, but I am now having a problem tiding it up.
To simplify. I have 2 columns, both containing data formatted as text, each column has some data, but on different rows.
I need to merge the 2 columns without overwriting the data on the second column, with blank data from the first column, and without the column shrinking or growing.
Here is a section of my spreadsheet that needs merging : Excel-1.PNG
I have tried copy > Paste Special > Skip Blanks, but it just copies the column to the other - no merging.
Sheet1 apple pc sony camera lenovotablet apple laptop
Sheet2 sony television lenovopc
I need to compare Column A from Sheet2 with Sheet1 and where the values match, only replace THOSE values in Column B of Sheet1 with those in Column B of Sheet2. Hence, after the replacement, Sheet1 should look like (value for apple remains unchanged).
I have this sheet, which is just an example (the actual one has many more records). subset.xlsx
I received this sheet (again, example)... new.xlsx
I need to add the new sheet to the old sheet, so that they are merged into one sheet. Also, if the same "LOC" appears in both sheets, I need to overwrite all the records for that "LOC" in the old sheet with the records from the new sheet.
My code is working with respect to finding the right data, but it keeps overwriting itself on each loop through...I need it to copy/paste and then on the next loop, move down one cell...
I am working on multiple sheets that collate to an “averages” sheet. The Averages sheet would need to collate the information historically.
I need a code that can be assigned to a button so when it’s clicked, the figures for this week are added to the figures that were from last week. So for example.
Worksheet 10, Rows 12 – 20 have the data from the last 8 weeks.
Worksheet 09 has this weeks data and a button to push. When pushed it adds the data from this week to row 21 in Worksheet 10.
The following week the button would add the data to row 22 and so on.
Essentially each time the button is pressed it drops the information in a row one lower than the last time the button was pressed.
Perhaps, this question is much more related to Windows API but I thought of posting it here incase I get some more ideas.
I am looking forward to develop a program wherein I can prevent or avoid an Excel file being overwritten by a different file with the same name in the same location in windows explorer.
After a rapid search on the internet I have got something which I could use but that would just serve me the purpose of retreiving the overwritten file in windows explorer.
I have a problem with a certain tool that i've been trying to develop.
I have two sheets in my workbook. In the first one i choose a value from a list (in cell A2). After the value in the list is chosen, certain integers for that value appear in the right columns. (with blanks between them)
Next, I will press a button called "calculate" which works like this: If A2 can be found in Sheet 2 Column "Value" then the macro overwrites the integers found at the right of the A2 from those found in Sheet1.
If Sheet1(A2) is not found in the Column "value" then a new line is inserted at the end of the table like this.
A 1 3 6
Pls help me with this, I have a very close deadline and I don't think I can pull this off by myself in such little time.
I have some code written to duplicate a template and rename the copy to "Working Copy".
But if I run the code more than once, it breaks as VBA tries to overwrite the sheet with the same name.
Would I would like is for the macro to check to see it already exists and duplicate the copy with some type of incremental integer. Thus the first duplicate would be Working Copy 1, and if the macro is run again, the duplicated copy would be Working Copy 2, etc.
here is what I have so far:
Sub SCButton() Dim i As Integer 'for making Working Copy 1, 2, etc.
Sheets("SCTemplate").Select 'this file will eventually be hidden and thus the user with only see the wokring copies. Sheets("SCTemplate").Copy After:=Sheets(4) Sheets("SCTemplate (2)").Select 'some sort of If statement here to check for the sheets
I have created a code in which the information from Sheet 1 copies to Sheet 2 correctly. Every time I input new information for my click event (ticket sales/amount received/change due) I want this information to be displayed in Sheet 2. However, every time I start a new submission, the information overwrites on the second Row so that only one submission is displayed. I need to create a history of all submissions from Sheet 1. Here is the code that I have to copy Sheet 1 to Sheet 2:
VB: intRow = intRow + 1 If intRow = 1 Then intRow = intRow + 1 End If
I need a code that will copy any cells with data in range I3:I41 from sheet2 and paste it in sheet1 starting at cell B3. Then copy any cells with data in range I3:I41 from sheet3 and paste it in sheet1 starting at the next empty cell.
Here's the most important part: There will be formulas in Column D in Sheet 2 that I need to stay with each item. generating the desired result on Sheet 2!
I have amended the code below and have got it working. The problem I have now is that every time it loops it overwrites the data it wrote the previous loop
Offending line being ActiveSheet. Range ("A1: D30") = ValuesArray
I have known that somehow it should remember the last row and copy below this one but I cannot get it to work
Code: Sub Basic_Example_1() Dim MyPath As String, FilesInPath As String Dim MyFiles() As String Dim SourceRcount As Long, Fnum As Long Dim mybook As Workbook, BaseWks As Worksheet Dim sourceRange As Range, destrange As Range
I have a situation where I have to curve fit data, this can lead to different formulas being used with varying constants.
Is it possible to pickup a TEXT based formula and related constants from other cells, and then place this into another cell as a functioning formula. For Example
Cell A1 contains the formula as a text string whether it be y=a+bx+cx^2, or y=a+b/x, etc Cells A2:A6 contain the individual constants, a, b, c, etc
I would then want the VBA to read the text based formula and put it into an output cell as a functioning excel formulae.g
In cell B10: =a+b*A10+c*A10^2
I understand picking the constants up and putting the formula should not be too much of an issue, however trying to insert the variable form of the curve fit is the part that I am struggling with, and am unsure if possible.
I have an existing formula in a cell linking back to a start date only. determining how to add an additional formula to exclude weekends, and possibly holidays.
I'm having some trouble trying to get excel to input a formula into a cell. I'm still a novice at VBA right now, so I don't think my problem will be too much of a brain buster.
I want a formula in Cell A6 (and I already know it correctly works) in this format: =E6&VLOOKUP(I6,'FA-Fund Data'!B$1:C$2000,2,FALSE)&J6
I have a worksheet that has macro events attached to command buttons. When a ‘Start’ command button is clicked, a timer begins counting in seconds and displays the value in cell B3 until a ‘Stop’ command button is clicked. The event works flawlessly as long as I don’t open up another workbook (to continue working in Excel).
When the second workbook is open…then time stops working in the workbook where the macro was created…and starts displaying the ‘timer count in seconds’ in the new active workbook--which overwrites/destroys the data in the newly opened workbook. When I go back to the original book that called the macro…it continues counting again.
I need this timer to continue running in the workbook with the command buttons (in the background) while I work on other worksheets in other books. Is there a way to keep the timer running no matter how many other workbooks are opened and prevent it from overwriting whatever sheet is active? This code in the Increment Sub below ‘overwrites’ the contents of cell B3 on whatever sheet is active---and stops the timer in the on the sheet with the ‘Start’ command button.
Is it possible to write a formula that skips x number of cells and have the formula autoincrement as usual. For an examples lets say I want to skip 3 cells and I have entered in the cells listed:
A1= "1" A2= "2" A3= "3"
Then I type in the simple formula in the cell B1= "=A1"
and then drag down but it skips 3 cells so then
B5= "=A2"
B9= "=A3"
If it didn't skip then B1= "=A1" B2= "=A2" B3= "=A3"
this is just an example as I will be writing more complex formulas and need some thing that I can write into the formula so that it skips.
I would like to copy a formula in a cell and then paste only the text of the formula, but I can't figure it out. Basically, I would like to avoid going into the cells and absolute referencing or hitting F2, then copying the text.
When I hit "Ctrl C" to copy the cell, then hit "Alt/E/S/F/Enter" to paste the formula, it is just like a regular copy/paste formula-wise in that the references move.