ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Skipping rows with VBA (https://www.excelbanter.com/excel-discussion-misc-queries/84827-skipping-rows-vba.html)

Jeff

Skipping rows with VBA
 
Hello,
Here's my VBA Procedure.
I need to help: Is it possible to only evaluate the odd-numbered rows?

Sub trimit()
Dim a As Long
x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
--
Regards,
Jeff


Chip Pearson

Skipping rows with VBA
 
Jeff,

Try

x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If a Mod 2 = 1 Then
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
End If
Next a

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jeff" wrote in message
...
Hello,
Here's my VBA Procedure.
I need to help: Is it possible to only evaluate the
odd-numbered rows?

Sub trimit()
Dim a As Long
x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
--
Regards,
Jeff




Jeff

Skipping rows with VBA
 
Thank you Chip,
I made a misake. I meant even-numbered rows. Can you help?

--
Regards,
Jeff



"Chip Pearson" wrote:

Jeff,

Try

x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If a Mod 2 = 1 Then
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
End If
Next a

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jeff" wrote in message
...
Hello,
Here's my VBA Procedure.
I need to help: Is it possible to only evaluate the
odd-numbered rows?

Sub trimit()
Dim a As Long
x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
--
Regards,
Jeff





Chip Pearson

Skipping rows with VBA
 
For even numbered rows, change

If a Mod 2 = 1 Then

to

If a Mod 2 = 0 Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jeff" wrote in message
...
Thank you Chip,
I made a misake. I meant even-numbered rows. Can you help?

--
Regards,
Jeff



"Chip Pearson" wrote:

Jeff,

Try

x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If a Mod 2 = 1 Then
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
End If
Next a

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jeff" wrote in message
...
Hello,
Here's my VBA Procedure.
I need to help: Is it possible to only evaluate the
odd-numbered rows?

Sub trimit()
Dim a As Long
x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
--
Regards,
Jeff







Dave Peterson

Skipping rows with VBA
 
Another way:

For a = 1 To 100 Step 2
or
For a = 2 To 100 step 2

(depending on which ones you want to skip.)

Jeff wrote:

Hello,
Here's my VBA Procedure.
I need to help: Is it possible to only evaluate the odd-numbered rows?

Sub trimit()
Dim a As Long
x = Mid(Application.Trim(Range("a5")), 12, 20)
For a = 1 To 100
If Cells(a, 1).Value 0 Then
Cells(a, 2).Value = x
Else
Cells(a, 2).Value = 0
End If
--
Regards,
Jeff


--

Dave Peterson


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

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