Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default autofill macro has error when there is nothing to fill.

Hello all:

I need your help with the following:

Part of my macro includes the portion below. The macro works fine whe
I have more than 1 line of data i.e. I have items in row 2, 3 (row 1 i
a heading) e.t.c. But today, my data only includes information for
account, i.e. I only have info in row 2.

When I ran the macro, I was getting an error, and when I pressed debu
the "Selection.AutoFill Destination:=Range("K2:M" & ro$)" wa
highlighted in my code. So I thought maybe because I only have 1 ro
of data in row 2 and the code does not have anywhere else to autofill
what do I add to this code so that when there is only 1 line of dat
i.e. in row 2 only, it should not autofill? Do you think that wil
solve the problem?

Thanks you so much for helping me.



Range("K2").Select
ActiveCell.FormulaR1C1
"=IF(ISNA(VLOOKUP(RC[-9],bast,1,0)),"""",""YES"")"
Range("L2").Select
ActiveCell.FormulaR1C1 = _

"=IF(ISNA(VLOOKUP(RC[-10],bast,1,0)),"""",VLOOKUP(RC[-10],bast,7,0))"
Range("M2").Select
ActiveCell.FormulaR1C1 = _

"=IF(ISNA(VLOOKUP(RC[-11],ban,15,0)),"""",IF(VLOOKUP(RC[-11],ban,15,0)<=0,""Past"",IF(VLOOKUP(RC[-11],bast,15,0)5,""On"",""Yep"")))"
Range("b1").Select
Selection.End(xlDown).Select
ro$ = ActiveCell.Row
Range("K2:M2").Select
Selection.AutoFill Destination:=Range("K2:M" & ro$

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default autofill macro has error when there is nothing to fill.

first, I wouldn't use a string variable to represent the row number:

Option Explicit
Sub testme()

Dim myRow As Long

Range("K2").FormulaR1C1 = _
"=IF(ISNA(VLOOKUP(RC[-9],bast,1,0)),"""",""YES"")"
Range("L2").FormulaR1C1 = _
"=IF(ISNA(VLOOKUP(RC[-10],bast,1,0)),"""",VLOOKUP(RC[-10],bast,7,0))"
Range("M2").FormulaR1C1 = _
"=IF(ISNA(VLOOKUP(RC[-11],ban,15,0)),""""," _
& "IF(VLOOKUP(RC[-11],ban,15,0)<=0,""Past""," _
& "IF(VLOOKUP(RC[-11],bast,15,0)5,""On"",""Yep"")))"


myRow = Range("b1").End(xlDown).Row

If myRow 2 Then
Range("K2:m2").AutoFill _
Destination:=Range("K2:M" & myRow)
End If

End Sub


Just check to see what that row is. If it's not bigger than 2, then don't do
it.




"RichardO <" wrote:

Hello all:

I need your help with the following:

Part of my macro includes the portion below. The macro works fine when
I have more than 1 line of data i.e. I have items in row 2, 3 (row 1 is
a heading) e.t.c. But today, my data only includes information for 1
account, i.e. I only have info in row 2.

When I ran the macro, I was getting an error, and when I pressed debug
the "Selection.AutoFill Destination:=Range("K2:M" & ro$)" was
highlighted in my code. So I thought maybe because I only have 1 row
of data in row 2 and the code does not have anywhere else to autofill,
what do I add to this code so that when there is only 1 line of data
i.e. in row 2 only, it should not autofill? Do you think that will
solve the problem?

Thanks you so much for helping me.

Range("K2").Select
ActiveCell.FormulaR1C1 =
"=IF(ISNA(VLOOKUP(RC[-9],bast,1,0)),"""",""YES"")"
Range("L2").Select
ActiveCell.FormulaR1C1 = _

"=IF(ISNA(VLOOKUP(RC[-10],bast,1,0)),"""",VLOOKUP(RC[-10],bast,7,0))"
Range("M2").Select
ActiveCell.FormulaR1C1 = _

"=IF(ISNA(VLOOKUP(RC[-11],ban,15,0)),"""",IF(VLOOKUP(RC[-11],ban,15,0)<=0,""Past"",IF(VLOOKUP(RC[-11],bast,15,0)5,""On"",""Yep"")))"
Range("b1").Select
Selection.End(xlDown).Select
ro$ = ActiveCell.Row
Range("K2:M2").Select
Selection.AutoFill Destination:=Range("K2:M" & ro$)

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default autofill macro has error when there is nothing to fill.

Thanks much Dave.


Richard

--
Message posted from http://www.ExcelForum.com

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
Can Autofill be Defaulted to copy cells instead of fill series Barry A&P Setting up and Configuration of Excel 3 January 26th 10 01:06 AM
Autofill & On Error Resume Next Dandelo Excel Discussion (Misc queries) 2 August 21st 08 07:14 PM
How do I get AutoFill to fill dates with time without rounding. PCF Excel Worksheet Functions 5 February 27th 08 07:49 AM
Autofill default: I want Fill Without Formatting Frustrated by Autofill Excel Discussion (Misc queries) 0 January 9th 07 03:39 PM
Can I use AutoFill or a formula to fill a series of letters? tadpgk835 Excel Discussion (Misc queries) 3 April 28th 05 02:46 PM


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

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"