PDA

View Full Version : Help with my code - I want to clear any formulas when pasting



markpem
03-03-2015, 07:47 AM
Hello

I have some code which works really well:-




Dim s1rw As Long, s2rw As Long, col As Long, endcol As Long
Cancel = True ' Ignore error messages as first column is LOCKED
Sheets("Page2").Select
With Sheets("Page1")
s2rw = 3 ' Adjust to first data row #
endcol = .Cells(s2rw - 1, 1).End(xlToRight).Column
Do Until .Cells(s2rw, 1).Value = "" ' Loop through case #s
s1rw = 0
On Error Resume Next
s1rw = Cells.Find(What:=.Cells(s2rw, 1).Value, LookIn:=xlFormulas, LookAt:=xlWhole).Row
On Error GoTo 0

If s1rw > 0 Then ' Found case #
For col = 2 To endcol ' Loop through columns
If Cells(s1rw, col).Value <> "" Then
If IsDate(Cells(s1rw, col).Value) Then
.Cells(s2rw, col).Value = Format(Cells(s1rw, col).Value, "mm/dd/yyyy")
Else
.Cells(s2rw, col).Value = Cells(s1rw, col).Value
End If
End If
Next
End If
s2rw = s2rw + 1
Loop
.Select
End With
End Sub


However in page 1 I sometimes have formulas. I want my in page2 to copy over and clear the formula as the formula is then changing the pasted data.

Can anyone please help!!

Yongle
03-03-2015, 03:54 PM
I think you need to be a lot more specific if you would like a good answer to match "the code that works really well".
"Sometimes I have formulas" - that does not really tell us very much does it?

Is it possible to clear everything from "page1" before you paste from "page2"?