ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Executing two statements in a for loop (https://www.excelbanter.com/excel-programming/381753-executing-two-statements-loop.html)

[email protected]

Executing two statements in a for loop
 
Hey guys I am new at macos

I basically have a column with both numbers and blank cells (column H).
I am trying to recognize only the numbers and copy them in the adjacent
column one after another.
When the cell is actually a number, I would like to increment a counter
starting from cell i11.
If I try to add a second If statement in the for loop for the sole
purpose of incrementing the counter I get an error

here is the code:

Sub rechercheFinale2()
Dim cell As Range
Dim index As Integer
index = 11
For Each cell In Range("H11:H402")
If IsNumeric(cell.Value) = True Then
Worksheets("Sheet1").Rows(index).Columns(9).Value = cell.Value
index = index + 1
Next cell
End Sub



thank you guys


Bob Phillips

Executing two statements in a for loop
 
Sub rechercheFinale2()
Dim cell As Range
Dim index As Integer
index = 11
For Each cell In Range("H11:H402")
If IsNumeric(cell.Value) Then
cell.Value.Copy Worksheets("Sheet1").Cells(index, "I").Value
index = index + 1
End If
Next cell
End Sub



--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


wrote in message
oups.com...
Hey guys I am new at macos

I basically have a column with both numbers and blank cells (column H).
I am trying to recognize only the numbers and copy them in the adjacent
column one after another.
When the cell is actually a number, I would like to increment a counter
starting from cell i11.
If I try to add a second If statement in the for loop for the sole
purpose of incrementing the counter I get an error

here is the code:

Sub rechercheFinale2()
Dim cell As Range
Dim index As Integer
index = 11
For Each cell In Range("H11:H402")
If IsNumeric(cell.Value) = True Then
Worksheets("Sheet1").Rows(index).Columns(9).Value = cell.Value
index = index + 1
Next cell
End Sub



thank you guys




[email protected]

Executing two statements in a for loop
 
Its funny, I noticed the code I was working with actually had two index

Sub rechercheFinale2()
Dim cell As Range
Dim index As Integer
index = 11
For Each cell In Range("H11:H402")
index = index + 1
If IsNumeric(cell.Value) = True Then
Worksheets("Sheet1").Rows(index).Columns(9).Value = cell.Value
index = index + 1
End If
Next cell
End Sub

the version I posted actually works, but yours is cleaner

Thank you for your help


Bob Phillips a écrit :
Sub rechercheFinale2()
Dim cell As Range
Dim index As Integer
index = 11
For Each cell In Range("H11:H402")
If IsNumeric(cell.Value) Then
cell.Value.Copy Worksheets("Sheet1").Cells(index, "I").Value
index = index + 1
End If
Next cell
End Sub



--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


wrote in message
oups.com...
Hey guys I am new at macos

I basically have a column with both numbers and blank cells (column H).
I am trying to recognize only the numbers and copy them in the adjacent
column one after another.
When the cell is actually a number, I would like to increment a counter
starting from cell i11.
If I try to add a second If statement in the for loop for the sole
purpose of incrementing the counter I get an error

here is the code:

Sub rechercheFinale2()
Dim cell As Range
Dim index As Integer
index = 11
For Each cell In Range("H11:H402")
If IsNumeric(cell.Value) = True Then
Worksheets("Sheet1").Rows(index).Columns(9).Value = cell.Value
index = index + 1
Next cell
End Sub



thank you guys




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

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