ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro to fill in rows with blanks (https://www.excelbanter.com/excel-discussion-misc-queries/242092-macro-fill-rows-blanks.html)

hnyb1

macro to fill in rows with blanks
 
Hi.

Can anyone tell me what is wrong with this code? I know I've used an IF
statement in the past, but code fills in formula for all rows without IF
statement. As soon as I add IF statement, stops working entirely. Thanks,
in advance.

Sub trynext()

Sheets("Sheet3").Select
LastRow = Cells(Rows.Count, 3).End(xlUp).Row
With ActiveSheet
For rowi = 2 To LastRow
If Cells(i, 2) = "" Then
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"
End If
Next
End With
End Sub

Gary''s Student

macro to fill in rows with blanks
 
i is undefined.
--
Gary''s Student - gsnu200902


"hnyb1" wrote:

Hi.

Can anyone tell me what is wrong with this code? I know I've used an IF
statement in the past, but code fills in formula for all rows without IF
statement. As soon as I add IF statement, stops working entirely. Thanks,
in advance.

Sub trynext()

Sheets("Sheet3").Select
LastRow = Cells(Rows.Count, 3).End(xlUp).Row
With ActiveSheet
For rowi = 2 To LastRow
If Cells(i, 2) = "" Then
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"
End If
Next
End With
End Sub


Don Guillett

macro to fill in rows with blanks
 
Sub trynextSAS()
With Sheets("sheet3")
lr = .Cells(Rows.Count, 3).End(xlUp).Row
For i = 2 To lr
If .Cells(i, 2) = "" Then
.Cells(i, "b") = "4/28/2009"
.Cells(i, "e") = 1
End If
Next
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"hnyb1" wrote in message
...
Hi.

Can anyone tell me what is wrong with this code? I know I've used an IF
statement in the past, but code fills in formula for all rows without IF
statement. As soon as I add IF statement, stops working entirely.
Thanks,
in advance.

Sub trynext()

Sheets("Sheet3").Select
LastRow = Cells(Rows.Count, 3).End(xlUp).Row
With ActiveSheet
For rowi = 2 To LastRow
If Cells(i, 2) = "" Then
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"
End If
Next
End With
End Sub



Susan

macro to fill in rows with blanks
 
this line

If Cells(i, 2) = "" Then

seems like it should be

If Cells(rowi, 2) = "" Then

in addition, this code:
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"

could be shortened up by removing the selects:
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Formula = "1"

hth
:)
susan



On Sep 9, 9:04*am, hnyb1 wrote:
Hi.

Can anyone tell me what is wrong with this code? *I know I've used an IF
statement in the past, but code fills in formula for all rows without IF
statement. *As soon as I add IF statement, stops working entirely. *Thanks,
in advance.

Sub trynext()

* * Sheets("Sheet3").Select
* * LastRow = Cells(Rows.Count, 3).End(xlUp).Row
* * With ActiveSheet
* * * * For rowi = 2 To LastRow
* * * * If Cells(i, 2) = "" Then
* * * * * * Cells(rowi, "b").Select
* * * * * * Cells(rowi, "b").Formula = "4/28/2009"
* * * * * * Cells(rowi, "e").Select
* * * * * * Cells(rowi, "e").Formula = "1"
* * * * End If
* * * * Next
* * * * End With
End Sub



hnyb1

macro to fill in rows with blanks
 
Thanks so much! That was exactly it!!!

"Susan" wrote:

this line

If Cells(i, 2) = "" Then

seems like it should be

If Cells(rowi, 2) = "" Then

in addition, this code:
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"

could be shortened up by removing the selects:
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Formula = "1"

hth
:)
susan



On Sep 9, 9:04 am, hnyb1 wrote:
Hi.

Can anyone tell me what is wrong with this code? I know I've used an IF
statement in the past, but code fills in formula for all rows without IF
statement. As soon as I add IF statement, stops working entirely. Thanks,
in advance.

Sub trynext()

Sheets("Sheet3").Select
LastRow = Cells(Rows.Count, 3).End(xlUp).Row
With ActiveSheet
For rowi = 2 To LastRow
If Cells(i, 2) = "" Then
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"
End If
Next
End With
End Sub




Don Guillett

macro to fill in rows with blanks
 
Why select. Did you look at mine

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"hnyb1" wrote in message
...
Thanks so much! That was exactly it!!!

"Susan" wrote:

this line

If Cells(i, 2) = "" Then

seems like it should be

If Cells(rowi, 2) = "" Then

in addition, this code:
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"

could be shortened up by removing the selects:
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Formula = "1"

hth
:)
susan



On Sep 9, 9:04 am, hnyb1 wrote:
Hi.

Can anyone tell me what is wrong with this code? I know I've used an
IF
statement in the past, but code fills in formula for all rows without
IF
statement. As soon as I add IF statement, stops working entirely.
Thanks,
in advance.

Sub trynext()

Sheets("Sheet3").Select
LastRow = Cells(Rows.Count, 3).End(xlUp).Row
With ActiveSheet
For rowi = 2 To LastRow
If Cells(i, 2) = "" Then
Cells(rowi, "b").Select
Cells(rowi, "b").Formula = "4/28/2009"
Cells(rowi, "e").Select
Cells(rowi, "e").Formula = "1"
End If
Next
End With
End Sub






All times are GMT +1. The time now is 09:21 AM.

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