ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can i avoid mutiple copy pasting of this code ? (https://www.excelbanter.com/excel-programming/370088-can-i-avoid-mutiple-copy-pasting-code.html)

Corey

Can i avoid mutiple copy pasting of this code ?
 
Sub Dates()
If Worksheets("Inductions Update Page").Range("c8") < "" Then
Worksheets("Print & Shading Page").Range("C8") = _
Worksheets("Induction Frequency Page").Range("C8") + _
Worksheets("Inductions Update Page").Range("C8")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If
If Worksheets("Inductions Update Page").Range("c9") < "" Then
Worksheets("Print & Shading Page").Range("C9") = _
Worksheets("Induction Frequency Page").Range("C9") + _
Worksheets("Inductions Update Page").Range("C9")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If

End Sub

I need to do the above coding to all cells the the range of (C8:R30)

Is there an easier way other than how i have began, that being each step range changed to the next cell?


Corey....

NickHK

Can i avoid mutiple copy pasting of this code ?
 
Corey,
Something like this ?

Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next

There's no point in this line:
Worksheets("Induction Update Page").Range("C9") = ""
because you are already checking that it is < "".

NickHK

"Corey" wrote in message
...
Sub Dates()
If Worksheets("Inductions Update Page").Range("c8") < "" Then
Worksheets("Print & Shading Page").Range("C8") = _
Worksheets("Induction Frequency Page").Range("C8") + _
Worksheets("Inductions Update Page").Range("C8")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If
If Worksheets("Inductions Update Page").Range("c9") < "" Then
Worksheets("Print & Shading Page").Range("C9") = _
Worksheets("Induction Frequency Page").Range("C9") + _
Worksheets("Inductions Update Page").Range("C9")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If

End Sub

I need to do the above coding to all cells the the range of (C8:R30)

Is there an easier way other than how i have began, that being each step
range changed to the next cell?


Corey....



Corey

Can i avoid mutiple copy pasting of this code ?
 
Thanks Nick,

Are you saying that i need to still enter MULTIPLE entries or this code:
__________________________________________________ ___
sub dates()
Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next
End Sub
__________________________________________________ ___ you posted is ALL i
need?

Corey....

"NickHK" wrote in message
...
Corey,
Something like this ?

Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next

There's no point in this line:
Worksheets("Induction Update Page").Range("C9") = ""
because you are already checking that it is < "".

NickHK

"Corey" wrote in message
...
Sub Dates()
If Worksheets("Inductions Update Page").Range("c8") < "" Then
Worksheets("Print & Shading Page").Range("C8") = _
Worksheets("Induction Frequency Page").Range("C8") + _
Worksheets("Inductions Update Page").Range("C8")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If
If Worksheets("Inductions Update Page").Range("c9") < "" Then
Worksheets("Print & Shading Page").Range("C9") = _
Worksheets("Induction Frequency Page").Range("C9") + _
Worksheets("Inductions Update Page").Range("C9")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If

End Sub

I need to do the above coding to all cells the the range of (C8:R30)

Is there an easier way other than how i have began, that being each step
range changed to the next cell?


Corey....





Corey

Can i avoid mutiple copy pasting of this code ?
 
Got it, does the lot in a one-r.
You just saved me a hell of a lot a data code entry thanks
Corey....


"Corey" wrote in message
...
Thanks Nick,

Are you saying that i need to still enter MULTIPLE entries or this code:
__________________________________________________ ___
sub dates()
Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next
End Sub
__________________________________________________ ___ you posted is ALL i
need?

Corey....

"NickHK" wrote in message
...
Corey,
Something like this ?

Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next

There's no point in this line:
Worksheets("Induction Update Page").Range("C9") = ""
because you are already checking that it is < "".

NickHK

"Corey" wrote in message
...
Sub Dates()
If Worksheets("Inductions Update Page").Range("c8") < "" Then
Worksheets("Print & Shading Page").Range("C8") = _
Worksheets("Induction Frequency Page").Range("C8") + _
Worksheets("Inductions Update Page").Range("C8")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If
If Worksheets("Inductions Update Page").Range("c9") < "" Then
Worksheets("Print & Shading Page").Range("C9") = _
Worksheets("Induction Frequency Page").Range("C9") + _
Worksheets("Inductions Update Page").Range("C9")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If

End Sub

I need to do the above coding to all cells the the range of (C8:R30)

Is there an easier way other than how i have began, that being each step
range changed to the next cell?


Corey....







Jim May

Can i avoid mutiple copy pasting of this code ?
 
Corey:
FYI,,
The "For Each" keywords indicate a looping of all elements of a
collection,
which in this case are Cells C8 to R30 (23 rows 16 cols) all 368 of
them.

"Corey" wrote in message
:

Thanks Nick,

Are you saying that i need to still enter MULTIPLE entries or this code:
__________________________________________________ ___
sub dates()
Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next
End Sub
__________________________________________________ ___ you posted is ALL i
need?

Corey....

"NickHK" wrote in message
...

Corey,
Something like this ?

Dim Cell As Range
Dim PSP As Worksheet
Dim IFP As Worksheet

Set PSP = Worksheets("Print & Shading Page")
Set IFP = Worksheets("Induction Frequency Page")

For Each Cell In Worksheets("Inductions Update Page").Range("C8:R30")
With Cell
If .Value < "" Then
PSP.Range(.Address).Value = IFP.Range(.Address).Value + .Value
End If
End With
Next

There's no point in this line:
Worksheets("Induction Update Page").Range("C9") = ""
because you are already checking that it is < "".

NickHK

"Corey" wrote in message
...
Sub Dates()
If Worksheets("Inductions Update Page").Range("c8") < "" Then
Worksheets("Print & Shading Page").Range("C8") = _
Worksheets("Induction Frequency Page").Range("C8") + _
Worksheets("Inductions Update Page").Range("C8")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If
If Worksheets("Inductions Update Page").Range("c9") < "" Then
Worksheets("Print & Shading Page").Range("C9") = _
Worksheets("Induction Frequency Page").Range("C9") + _
Worksheets("Inductions Update Page").Range("C9")
Else
Worksheets("Induction Update Page").Range("C9") = ""
End If

End Sub

I need to do the above coding to all cells the the range of (C8:R30)

Is there an easier way other than how i have began, that being each step
range changed to the next cell?


Corey....





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com