Macro creating zero entries

johngio

Board Regular
Joined
Jan 28, 2005
Messages
174
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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
 
Upvote 0

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

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?

Disable AdBlock

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
Back
Top