Excel - Send value of cell to target

Last update on November 2, 2009 12:23 PM by aakai1056
Published by aakai1056

Excel - Send value of cell to target






Issue


Is it possible to send the value of a cell (copy and paste special) to another cell where the value would not be disturbed when the source value changes to '0'?
My payroll calculator summary worksheet gets information from other worksheets each week within the Excel file and calculates the current week's payroll. The previous week had values, but now, during the current week, the cells for the previous week are 0.
My goal is to retain the previous weeks values in another cell array so that I may have a running total for the month.


Example:
A3 has the formula:

=IF(A3='Payroll Calculator'!M2,VLOOKUP(H1,'Payroll Calculator'!$B$3:$M$28,8,FALSE),0) 


That value needs to be posted to K3 but only if more than '0'.
If a3 returns a value of '0' then any value greater than '0' that was previously posted in k3 would be left alone.

I have been easily doing this manually by simply copying the values that I want to save, then using the 'paste special' command and choosing 'values', paste to the target. The 'skip blanks' does nothing. The macro:

Sub Macro1()
'
' Macro1 Macro
'

'
Range("C3").Select
ActiveWindow.ScrollRow = 10
Range("C3:I52").Select
Selection.Copy
Range("K3").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
True, Transpose:=False
Range("K3").Select
Application.CutCopyMode = False
End Sub


Over-writes the previous weeks' values with zeros whether I choose skip blanks or not. (Probably because the cells are zeros, not blank!)

I am working with the array A3:I54 and wish to copy and paste any values greater than '0' to K3:Q54 retaining any values that were previously posted in K3:Q54 that are greater than '0'

Solution


Maybe this can get you in the right direction if my interpretation is correct.
This will compare column A with what is currently in column K........


A1 compares the value in K1
A2 compares the value in K2
etc....

If column A is zero and column K is greater than zero, then keep the value in column K. Otherwise copy the
value in column A to column K.

Sub Macro1() 

Dim j 
j = 3 

Do Until Range("A" & j) = "" 

If Range("A" & j) = 0 Then 

Range("K" & j) = Range("K" & j) 

Else 

Range("K" & j) = Range("A" & j) 

End If 

j = j + 1 

Loop 


End Sub


To add multiple columns, make the macro looks like "C:K"

Sub Macro1() 

Dim j 
j = 3 

Do Until Range("C" & j) = "" 

If Range("C" & j) = 0 Then 
Range("K" & j) = Range("K" & j) 
Else 
Range("K" & j) = Range("C" & j) 
End If 

If Range("D" & j) = 0 Then 
Range("L" & j) = Range("L" & j) 
Else 
Range("L" & j) = Range("D" & j) 
End If 

If Range("E" & j) = 0 Then 
Range("M" & j) = Range("M" & j) 
Else 
Range("M" & j) = Range("E" & j) 
End If 

If Range("F" & j) = 0 Then 
Range("N" & j) = Range("N" & j) 
Else 
Range("N" & j) = Range("F" & j) 
End If 

If Range("G" & j) = 0 Then 
Range("O" & j) = Range("O" & j) 
Else 
Range("O" & j) = Range("G" & j) 
End If 

If Range("H" & j) = 0 Then 
Range("P" & j) = Range("P" & j) 
Else 
Range("P" & j) = Range("H" & j) 
End If 

If Range("I" & j) = 0 Then 
Range("Q" & j) = Range("Q" & j) 
Else 
Range("Q" & j) = Range("I" & j) 
End If 


j = j + 1 

Loop 


End Sub

Note


Thanks to WutUp WutUp for this tip on the forum.
Best answers for « Excel Send value of cell to target » in :
Excel – Formula for cell calculation Show Excel – Formula for cell calculation Issue Solution Note Issue Simple formula of =J3-SUM(L3:X3) BUT if J3 is empty then I want the formula to run as =C3-SUM(L3:X3) What is the proper formula to get the calculation to utilize J3 if...
[Excel]changing cell formula to text Show[Excel]changing cell formula to text Issue Solution Notes Issue Consider that I have: In cell A4, it contains a formula =Sum(A1:B3)+A3/B2. How to extract this formula in cell A6 as a string of text? That is ... I want cell A6...
Excel tips : How to insert date in a cell ShowExcel tips : How to insert date in a cell Below are some tips on how to insert date and time in an excel cell for a specific purpose:- To insert current date, press CTRL + ; in the chosen cell. To insert current time, press CTRL+...
[VBA] Detecting changes in cell Show[VBA] Detecting changes in cell The Event Change feature of a sheet will detects the change in the active cell but it gives no information about the content. The example given below will help you to find out if the cell was changed,...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...