Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default repeat code until row 24

I am trying to move the contents of column E to column D if column B -
C. The code I have works for one row, I have tried and failed many
times in an attempt to repeat it until row 24. How would I make this
repeat each row until 24. (It starts on 2) I am sure there is an easier
way to do this, but my abilities are lacking.

Private Sub CommandButton1_Click()
If Range("B2") = "C" Then
If Range("E2") < "" Then
With Range("E2").Copy
Range("D2").PasteSpecial Paste:=xlValues
Range("E2").Clear
End With
End If
End If
End Sub

Thanks,
Josh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default repeat code until row 24

Why not use worksheet formulae?

D2: = IF(AND(E2<"",B2="C"),E2,"")

and copy down.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Josh" wrote in message
...
I am trying to move the contents of column E to column D if column B -
C. The code I have works for one row, I have tried and failed many
times in an attempt to repeat it until row 24. How would I make this
repeat each row until 24. (It starts on 2) I am sure there is an easier
way to do this, but my abilities are lacking.

Private Sub CommandButton1_Click()
If Range("B2") = "C" Then
If Range("E2") < "" Then
With Range("E2").Copy
Range("D2").PasteSpecial Paste:=xlValues
Range("E2").Clear
End With
End If
End If
End Sub

Thanks,
Josh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default repeat code until row 24

Private Sub CommandButton1_Click()
for i = 0 to 23
If Range("B2").Offset(i,0) = "C" Then
If Range("E2").Offset(i,0) < "" Then
Range("E2").Offset(i,0).Copy
Range("D2").Offset(i,0).PasteSpecial Paste:=xlValues
Range("E2").Offset(i,0).Clear
End If
End If
End Sub

--
Regards,
Tom Ogilvy


"Josh" wrote in message
...
I am trying to move the contents of column E to column D if column B -
C. The code I have works for one row, I have tried and failed many
times in an attempt to repeat it until row 24. How would I make this
repeat each row until 24. (It starts on 2) I am sure there is an easier
way to do this, but my abilities are lacking.

Private Sub CommandButton1_Click()
If Range("B2") = "C" Then
If Range("E2") < "" Then
With Range("E2").Copy
Range("D2").PasteSpecial Paste:=xlValues
Range("E2").Clear
End With
End If
End If
End Sub

Thanks,
Josh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default repeat code until row 24

Hi Josh,
This should do it!

Sub Test()
Dim Rng As Range
Dim cel As Range

Set Rng = Range("E1:E24")

For Each cel In Rng
With cel
If .Offset(0, -3).Value = "C" Then
.Value = .Offset(0, -1).Value
.Offset(0, -1).ClearContents
End If
End With
Next




End Sub


Regards

Paul

"Josh" wrote in message
...
I am trying to move the contents of column E to column D if column B -
C. The code I have works for one row, I have tried and failed many
times in an attempt to repeat it until row 24. How would I make this
repeat each row until 24. (It starts on 2) I am sure there is an easier
way to do this, but my abilities are lacking.

Private Sub CommandButton1_Click()
If Range("B2") = "C" Then
If Range("E2") < "" Then
With Range("E2").Copy
Range("D2").PasteSpecial Paste:=xlValues
Range("E2").Clear
End With
End If
End If
End Sub

Thanks,
Josh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
repeat code remove AMIT BHOPAL Excel Worksheet Functions 3 December 25th 09 10:54 AM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
VBA Code To have a macro repeat on all sheets in a workbook carl Excel Worksheet Functions 3 November 3rd 05 07:48 PM
Repeat Code Repetitive Actions? chris Excel Discussion (Misc queries) 2 February 18th 05 11:30 PM
How to repeat code for 11 files? Milind Excel Programming 0 August 6th 03 10:09 PM


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

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

About Us

"It's about Microsoft Excel"