Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm trying to make the line
For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is the "usual" way:
Sub missive() n = Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & n) ' do something here Next End Sub -- Gary''s Student - gsnu200815 "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you for the help!
"Gary''s Student" wrote: Here is the "usual" way: Sub missive() n = Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & n) ' do something here Next End Sub -- Gary''s Student - gsnu200815 "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Do it this way Lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & Lastrow) 'do things next Mike "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, this seems to be doing the trick.
"Mike H" wrote: Hi, Do it this way Lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & Lastrow) 'do things next Mike "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is there a way to modify this so that rows with formulas generating blanks
are not counted? "Mike H" wrote: Hi, Do it this way Lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & Lastrow) 'do things next Mike "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
If you mean blanks in the middle of the range then maybe this Sub versive() Dim MyRange As Range lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row Worksheets("data").Range("A2:A" & lastrow).SpecialCells(xlConstants).Select Set MyRange = Selection For Each r In MyRange 'do things Next End Sub Mike "~L" wrote: Is there a way to modify this so that rows with formulas generating blanks are not counted? "Mike H" wrote: Hi, Do it this way Lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & Lastrow) 'do things next Mike "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Apparently, I meant:
Worksheets("Data").Range("A2:A" & Lastrow).SpecialCells(xlFormulas, xlNumbers).Select but you put me on the right track again. Thank you. "Mike H" wrote: Hi, If you mean blanks in the middle of the range then maybe this Sub versive() Dim MyRange As Range lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row Worksheets("data").Range("A2:A" & lastrow).SpecialCells(xlConstants).Select Set MyRange = Selection For Each r In MyRange 'do things Next End Sub Mike "~L" wrote: Is there a way to modify this so that rows with formulas generating blanks are not counted? "Mike H" wrote: Hi, Do it this way Lastrow = Worksheets("data").Cells(Rows.Count, "A").End(xlUp).Row For Each r In Worksheets("data").Range("A2:A" & Lastrow) 'do things next Mike "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
myvar = WorksheetFunction.CountA(Sheets("Data").Range("A1: A25000")) This will return the number of non blank cells in A1:A25000 Otherwise, you may want to consider re-evaluating your loop. First set the range set myrange=Worksheets("data").Range("A2:A25000") 'Then do this For each r in myrange if r = "" then 'do nothing Else 'do something End If Next r -- If this posting was helpful, please click on the Yes button. Regards, Michael Arch. "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you for your reply.
"Michael" wrote: Try this: myvar = WorksheetFunction.CountA(Sheets("Data").Range("A1: A25000")) This will return the number of non blank cells in A1:A25000 Otherwise, you may want to consider re-evaluating your loop. First set the range set myrange=Worksheets("data").Range("A2:A25000") 'Then do this For each r in myrange if r = "" then 'do nothing Else 'do something End If Next r -- If this posting was helpful, please click on the Yes button. Regards, Michael Arch. "~L" wrote: I'm trying to make the line For Each r In Worksheets("data").Range("A2:A25000") not evaluate blank cells by counting the number of populated cells using For Each r In Worksheets("data").Range("A2:A" & WorksheetFunction.CountA(Data!A2:A25000)) But when I do that, I get runtime error 1004. What is the correct way to phrase that? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Newbie: Problem with 'Select Case' testing syntax | Excel Programming | |||
Newbie: How to get another range? | Excel Programming | |||
Newbie syntax question | Excel Programming | |||
subscript out of range (newbie) | Excel Programming | |||
Proper Syntax Sought For NewBie Excel Programmer | Excel Programming |