# Macro creating zero entries

#### johngio

##### Board Regular
Hi all,

I have created a macro which looks for the letters f or l in the AA column. If once of these letters appears, I would like this to appear in either the Y (if the value is f) or Z (if the value is l) column:

6657
6657
6657
4029

However, rather than the numbers being inputted down 4 rows, I end up with a zero in the column in line with the l or f, and no numbers below it.

Here is my code:

Sub Macro5()
For iRow = 15 To 279
If Cells(iRow, 27) = "f" Then
Cells(iRow, 25) = 6657 And Cells(iRow + 1, 25) = 6657 And Cells(iRow + 2, 25) = 6657 And Cells(iRow + 3, 25) = 4029
ElseIf Cells(iRow, 27) = "l" Then
Cells(iRow, 26) = 6657 And Cells(iRow + 1, 26) = 6657 And Cells(iRow + 2, 26) = 6657 And Cells(iRow + 3, 26) = 4029

End If
Next iRow
End Sub

Any ideas?

Cheers

John

### Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

#### Andrew Poulsom

##### MrExcel MVP
You can't use a logical And like that. Try:

Code:
``````Sub Macro5()
For iRow = 15 To 279
If Cells(iRow, 27) = "f" Then
Cells(iRow, 25) = 6657
Cells(iRow + 1, 25) = 6657
Cells(iRow + 2, 25) = 6657
Cells(iRow + 3, 25) = 4029
ElseIf Cells(iRow, 27) = "l" Then
Cells(iRow, 26) = 6657
Cells(iRow + 1, 26) = 6657
Cells(iRow + 2, 26) = 6657
Cells(iRow + 3, 26) = 4029
End If
Next iRow
End Sub``````

Or use the colon between the assignment statements, eg:

Code:
``Cells(iRow, 25) = 6657: Cells(iRow + 1, 25) = 6657: Cells(iRow + 2, 25) = 6657: Cells(iRow + 3, 25) = 4029``

#### johngio

##### Board Regular
Thats what I was after!!

Thanks!

Replies
0
Views
138
Replies
0
Views
122
Replies
3
Views
154
Replies
7
Views
267
Replies
5
Views
243

1,170,942
Messages
5,872,857
Members
432,950
Latest member
ALeXceLBr

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

### Which adblocker are you using?

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

### Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back