Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,117
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default 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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill in Blanks with immediately above cell value Charles Excel Discussion (Misc queries) 4 May 15th 09 05:09 PM
Macro Formula for counting rows and doing a fill in afterwards Bud Excel Worksheet Functions 0 September 25th 08 08:10 PM
Fill blanks down column with cell above KtP Excel Discussion (Misc queries) 2 April 13th 08 10:34 PM
Fill Blanks Macro LLoraine Excel Discussion (Misc queries) 2 August 29th 07 03:12 PM
How do I fill in pivot table blanks? Lisan Excel Worksheet Functions 1 July 3rd 06 09:11 PM


All times are GMT +1. The time now is 12:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"