Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Next if blank in For Each Loop


Excel Experts,

My spreadsheet is similar to the following:

1 2
A Symbol Div
B DELL 1.23
C IBM 0
D MSFT 1.50

For each symbol, if the amount in the Div column is not zero, I want to
perform a series of steps. If the amount is zero, I want to skip to the next
symbol.

In the code below, when I try to run it, Excel gives an error, highlights
the Next within the If statement and says I can not have a Next without a
For.

How do I edit this procedure to make it go to the next symbol if the amount
in the Div column is zero.

Sub AddDiv( )

Set Symbols = Range("B1:D1")

Set HDiv = Range("A2")

For Each Symbol in Symbols

If Cells(Symbol.Row, HDiv.Column).Value = 0 Then

Next Symbol

End If

(Rest of Procedure)

Next Symbol

End Sub

Thanks in advance,
Alan

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Next if blank in For Each Loop

Sub AddDiv( )

dim Symbols as Range
dim HDiv as range

Set Symbols = Range("B1:D1")
Set HDiv = Range("A2")

For Each Symbol in Symbols
If Cells(Symbol.Row, HDiv.Column).Value = 0 Then
'skip it
else
(Rest of Procedure)
end if
Next Symbol

End Sub

achidsey wrote:

Excel Experts,

My spreadsheet is similar to the following:

1 2
A Symbol Div
B DELL 1.23
C IBM 0
D MSFT 1.50

For each symbol, if the amount in the Div column is not zero, I want to
perform a series of steps. If the amount is zero, I want to skip to the next
symbol.

In the code below, when I try to run it, Excel gives an error, highlights
the Next within the If statement and says I can not have a Next without a
For.

How do I edit this procedure to make it go to the next symbol if the amount
in the Div column is zero.

Sub AddDiv( )

Set Symbols = Range("B1:D1")

Set HDiv = Range("A2")

For Each Symbol in Symbols

If Cells(Symbol.Row, HDiv.Column).Value = 0 Then

Next Symbol

End If

(Rest of Procedure)

Next Symbol

End Sub

Thanks in advance,
Alan

--
achidsey


--

Dave Peterson
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
Paste blank cell row loop Ron Dean[_2_] Excel Programming 5 January 19th 06 08:59 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Excel VBA - Repeat for loop until blank rows rbelforti[_4_] Excel Programming 1 July 7th 04 10:48 PM
get for loop to go on after blank cell? john_t_h[_12_] Excel Programming 3 January 15th 04 06:35 AM


All times are GMT +1. The time now is 08:44 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"