Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default if not empty cells skip

I have this section of code which has been working fine, up until now, when i
try to run it it highlights the third line, I think this is because sometimes
there are no empty cells where i am trying to run it, can i get it to ignore
the code only if there are no empty cells?

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow + 1).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default if not empty cells skip

if you're selecting the row AFTER the last used row, then surely its blank
anyways??
whats the point of the code?

"Miree" wrote:

I have this section of code which has been working fine, up until now, when i
try to run it it highlights the third line, I think this is because sometimes
there are no empty cells where i am trying to run it, can i get it to ignore
the code only if there are no empty cells?

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow + 1).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default if not empty cells skip

Hi,

One way would be to simply trap the error and move on. Note also I've
combined you statement into a single line and got rid of all the select bits

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
On Error GoTo getmeout
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow +
1).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = ".."
getmeout:


Mike


"Miree" wrote:

I have this section of code which has been working fine, up until now, when i
try to run it it highlights the third line, I think this is because sometimes
there are no empty cells where i am trying to run it, can i get it to ignore
the code only if there are no empty cells?

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow + 1).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default if not empty cells skip

The row being selected is the one after the last used cell in column A which
could have data in

"Patrick Molloy" wrote:

if you're selecting the row AFTER the last used row, then surely its blank
anyways??
whats the point of the code?

"Miree" wrote:

I have this section of code which has been working fine, up until now, when i
try to run it it highlights the third line, I think this is because sometimes
there are no empty cells where i am trying to run it, can i get it to ignore
the code only if there are no empty cells?

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow + 1).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default if not empty cells skip

or, to avoid using GOTOs and setting error traps....

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

Set blanks = Range("B" & lngLastRow + 1 & ":DY" & lngLastRow +
1).Find(xlCellTypeBlanks)
If Not blanks Is Nothing Then
blanks.FormulaR1C1 = ".."
End If


"Mike H" wrote:

Hi,

One way would be to simply trap the error and move on. Note also I've
combined you statement into a single line and got rid of all the select bits

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
On Error GoTo getmeout
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow +
1).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = ".."
getmeout:


Mike


"Miree" wrote:

I have this section of code which has been working fine, up until now, when i
try to run it it highlights the third line, I think this is because sometimes
there are no empty cells where i am trying to run it, can i get it to ignore
the code only if there are no empty cells?

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("B" & lngLastRow + 1 & ":DY" & lngLastRow + 1).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = ".."

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
skip cells with zero values in chart (cells not empty) jhall@ifox Charts and Charting in Excel 3 June 2nd 09 02:11 PM
how do you skip empty cells or zeros when calculating the average soccerdav2003 Excel Programming 1 June 12th 08 12:01 AM
paste special / skip empty cells doesn't work!? Ivica TypeR Excel Worksheet Functions 3 July 10th 07 04:53 PM
How to skip empty cells while running a macro? saziz[_2_] Excel Programming 5 June 10th 04 11:16 PM
Skip empty and text cells Jason Morin[_3_] Excel Programming 3 April 2nd 04 10:22 PM


All times are GMT +1. The time now is 02:18 PM.

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

About Us

"It's about Microsoft Excel"