#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default Paste values - macro

Hi all
The following macro removes the formula in a cell.
Sub cpyvalue()

Dim i As Long, j As Long, K As Long, tmp As Long
j = Worksheets("school").Range("k1").Value

For i = 3 To j - 3

For K = 39 To 41
If Cells(i, K) = 0 Then
tmp = Cells(i, K - 9)
Cells(i, K - 9) = tmp
If Cells(i, K + 3) = 0 Then
tmp = Cells(i, K - 6)
Cells(i, K - 6) = tmp
End If
End If
Next K
Next i
Range("m2").Select
End Sub
It works fine. I want to incorporate two conditions.

1) If the cells(i, k-9) or cells(i, k-6) contains formula then only execute
the for loop of k.
2) Inside the for (k) loop, once Cells(i, K) = 0 condition fails, break
k-loop and goto next i.
The formula in cells(i, k-9) and cells(i, k-6) is simple sumif.
Any suggestions. Thanks all in advance.
With regards
Sreedhar
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 896
Default Paste values - macro

For i = 3 To j - 3
If Cells(i, K - 9).HasFormula and Cells(i, K - 6).HasFormula
Then
For K = 39 To 41
If Cells(i, K) = 0 Then
tmp = Cells(i, K - 9)
Cells(i, K - 9) = tmp
If Cells(i, K + 3) = 0 Then
tmp = Cells(i, K - 6)
Cells(i, K - 6) = tmp
End If
Else:
Exit For
GoTo lap
End If
End If
Next K
lap:
Next i


HIH


On 24 Mar, 09:18, yshridhar
wrote:
Hi all
The following macro removes the formula in a cell.
Sub cpyvalue()

* * Dim i As Long, j As Long, K As Long, tmp As Long
* * j = Worksheets("school").Range("k1").Value

* * For i = 3 To j - 3

* * * For K = 39 To 41
* * * * If Cells(i, K) = 0 Then
* * * * * * tmp = Cells(i, K - 9)
* * * * * * Cells(i, K - 9) = tmp
* * * * * * If Cells(i, K + 3) = 0 Then
* * * * * * tmp = Cells(i, K - 6)
* * * * * * Cells(i, K - 6) = tmp
* * * * * * End If
* * * * End If
* * * *Next K
* * Next i
* * Range("m2").Select
End Sub
It works fine. *I want to incorporate two conditions.

1) If the cells(i, k-9) or cells(i, k-6) contains formula then only execute
the for loop of k. *
2) Inside the for (k) loop, once Cells(i, K) = 0 condition fails, break
k-loop and goto next i.
The formula in cells(i, k-9) and cells(i, k-6) is simple sumif.
Any suggestions. *Thanks all in advance.
With regards
Sreedhar


For i = 3 To j - 3
If Cells(i, K - 9).HasFormula and Cells(i, K - 6).HasFormula
Then
For K = 39 To 41
If Cells(i, K) = 0 Then
tmp = Cells(i, K - 9)
Cells(i, K - 9) = tmp
If Cells(i, K + 3) = 0 Then
tmp = Cells(i, K - 6)
Cells(i, K - 6) = tmp
End If
Else:
Exit For
GoTo lap
End If
End If
Next K
lap:
Next i
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default Paste values - macro

Thanks alot JK. .hasformula has saved much of the time. Your modification
works for me.
With regards
Sreedhar

"Jarek Kujawa" wrote:

For i = 3 To j - 3
If Cells(i, K - 9).HasFormula and Cells(i, K - 6).HasFormula
Then
For K = 39 To 41
If Cells(i, K) = 0 Then
tmp = Cells(i, K - 9)
Cells(i, K - 9) = tmp
If Cells(i, K + 3) = 0 Then
tmp = Cells(i, K - 6)
Cells(i, K - 6) = tmp
End If
Else:
Exit For
GoTo lap
End If
End If
Next K
lap:
Next i


HIH


On 24 Mar, 09:18, yshridhar
wrote:
Hi all
The following macro removes the formula in a cell.
Sub cpyvalue()

Dim i As Long, j As Long, K As Long, tmp As Long
j = Worksheets("school").Range("k1").Value

For i = 3 To j - 3

For K = 39 To 41
If Cells(i, K) = 0 Then
tmp = Cells(i, K - 9)
Cells(i, K - 9) = tmp
If Cells(i, K + 3) = 0 Then
tmp = Cells(i, K - 6)
Cells(i, K - 6) = tmp
End If
End If
Next K
Next i
Range("m2").Select
End Sub
It works fine. I want to incorporate two conditions.

1) If the cells(i, k-9) or cells(i, k-6) contains formula then only execute
the for loop of k.
2) Inside the for (k) loop, once Cells(i, K) = 0 condition fails, break
k-loop and goto next i.
The formula in cells(i, k-9) and cells(i, k-6) is simple sumif.
Any suggestions. Thanks all in advance.
With regards
Sreedhar


For i = 3 To j - 3
If Cells(i, K - 9).HasFormula and Cells(i, K - 6).HasFormula
Then
For K = 39 To 41
If Cells(i, K) = 0 Then
tmp = Cells(i, K - 9)
Cells(i, K - 9) = tmp
If Cells(i, K + 3) = 0 Then
tmp = Cells(i, K - 6)
Cells(i, K - 6) = tmp
End If
Else:
Exit For
GoTo lap
End If
End If
Next K
lap:
Next i

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for copy and paste values excelnerd Excel Discussion (Misc queries) 3 March 8th 08 06:51 PM
A macro to paste values Matthew Excel Discussion (Misc queries) 2 September 17th 07 10:25 AM
Paste Values Macro John Calder New Users to Excel 4 May 28th 07 10:19 PM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM


All times are GMT +1. The time now is 10:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"