PC Review


Reply
Thread Tools Rate Thread

Clear if "#N/A" and Find End of Range, Fill Blanks

 
 
ryguy7272
Guest
Posts: n/a
 
      22nd Jul 2008
Simple problem seems to be turning into a complex problem. I want to clear
all cells that show #N/A.

Sub ClearRange()
Dim r As Range
Set r = Range("A2:A500")
For Each rr In r
If rr.Value = "#N/A" Then
rr.Offset(0, 1).Clear
End If
Next
End Sub

As an aside, I was trying to fill all blank cells with values from above
cells. It is easy to find the end of the range, but Excel seems to lose the
address of the last cell in the used range once I tell it to go to the first
cell in the used range (in my case it is A5)

Sub FindEnd()

Dim Rng As Range
Cells(Rows.Count, "A").End(xlUp).Select
ActiveCell.Select
Rng = ActiveCell

Selection.SpecialCells(xlCellTypeBlanks).Select
Range("A5:Rng").Select
Selection.FormulaR1C1 = "=R[-1]C"

End Sub


Any help with either macro would be greatly appreciated!!

Regards,
Ryan---

--
RyGuy
 
Reply With Quote
 
 
 
 
StumpedAgain
Guest
Posts: n/a
 
      22nd Jul 2008
Try something like the following. I'm unsure why you did
"rr.Offset(1,0).Clear" when you're trying to clear rr if rr.Value = "#N/A".
Maybe I'm missing something. Also, I added a line to insert the above cell
value into the newly cleared cell.

Sub ClearRange()
Dim rr, r As Range
Set r = Range("A2:A500")
For Each rr In r
If rr.Value = "#N/A" Then
rr.Clear
rr.value = rr.offset(-1,0).value
End If
Next rr
End Sub

If you're looking to fill more blank cells, something like the following
should work.

Sub FillBlanks()
Dim rr, r As Range
Set r = Range("A2:A500")
For Each rr In r
If rr.Value = "" Then
rr.value = rr.offset(-1,0).value
End If
Next rr
End Sub

Hope this helps!
--
-SA


"ryguy7272" wrote:

> Simple problem seems to be turning into a complex problem. I want to clear
> all cells that show #N/A.
>
> Sub ClearRange()
> Dim r As Range
> Set r = Range("A2:A500")
> For Each rr In r
> If rr.Value = "#N/A" Then
> rr.Offset(0, 1).Clear
> End If
> Next
> End Sub
>
> As an aside, I was trying to fill all blank cells with values from above
> cells. It is easy to find the end of the range, but Excel seems to lose the
> address of the last cell in the used range once I tell it to go to the first
> cell in the used range (in my case it is A5)
>
> Sub FindEnd()
>
> Dim Rng As Range
> Cells(Rows.Count, "A").End(xlUp).Select
> ActiveCell.Select
> Rng = ActiveCell
>
> Selection.SpecialCells(xlCellTypeBlanks).Select
> Range("A5:Rng").Select
> Selection.FormulaR1C1 = "=R[-1]C"
>
> End Sub
>
>
> Any help with either macro would be greatly appreciated!!
>
> Regards,
> Ryan---
>
> --
> RyGuy

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      22nd Jul 2008
For both macros i get:
I get a run time error '13'
Type Mismatch

Also, I need to find the used cell in Column A, because this list will
shrink grow each time data is pulled to create a report.

Any other ideas?

Thanks,
Ryan---

--
RyGuy


"StumpedAgain" wrote:

> Try something like the following. I'm unsure why you did
> "rr.Offset(1,0).Clear" when you're trying to clear rr if rr.Value = "#N/A".
> Maybe I'm missing something. Also, I added a line to insert the above cell
> value into the newly cleared cell.
>
> Sub ClearRange()
> Dim rr, r As Range
> Set r = Range("A2:A500")
> For Each rr In r
> If rr.Value = "#N/A" Then
> rr.Clear
> rr.value = rr.offset(-1,0).value
> End If
> Next rr
> End Sub
>
> If you're looking to fill more blank cells, something like the following
> should work.
>
> Sub FillBlanks()
> Dim rr, r As Range
> Set r = Range("A2:A500")
> For Each rr In r
> If rr.Value = "" Then
> rr.value = rr.offset(-1,0).value
> End If
> Next rr
> End Sub
>
> Hope this helps!
> --
> -SA
>
>
> "ryguy7272" wrote:
>
> > Simple problem seems to be turning into a complex problem. I want to clear
> > all cells that show #N/A.
> >
> > Sub ClearRange()
> > Dim r As Range
> > Set r = Range("A2:A500")
> > For Each rr In r
> > If rr.Value = "#N/A" Then
> > rr.Offset(0, 1).Clear
> > End If
> > Next
> > End Sub
> >
> > As an aside, I was trying to fill all blank cells with values from above
> > cells. It is easy to find the end of the range, but Excel seems to lose the
> > address of the last cell in the used range once I tell it to go to the first
> > cell in the used range (in my case it is A5)
> >
> > Sub FindEnd()
> >
> > Dim Rng As Range
> > Cells(Rows.Count, "A").End(xlUp).Select
> > ActiveCell.Select
> > Rng = ActiveCell
> >
> > Selection.SpecialCells(xlCellTypeBlanks).Select
> > Range("A5:Rng").Select
> > Selection.FormulaR1C1 = "=R[-1]C"
> >
> > End Sub
> >
> >
> > Any help with either macro would be greatly appreciated!!
> >
> > Regards,
> > Ryan---
> >
> > --
> > RyGuy

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Jul 2008
You could use:

If rr.Text = "#N/A" Then

or to test for any error in that cell:

If iserror(rr.Value) Then



ryguy7272 wrote:
>
> For both macros i get:
> I get a run time error '13'
> Type Mismatch
>
> Also, I need to find the used cell in Column A, because this list will
> shrink grow each time data is pulled to create a report.
>
> Any other ideas?
>
> Thanks,
> Ryan---
>
> --
> RyGuy
>
> "StumpedAgain" wrote:
>
> > Try something like the following. I'm unsure why you did
> > "rr.Offset(1,0).Clear" when you're trying to clear rr if rr.Value = "#N/A".
> > Maybe I'm missing something. Also, I added a line to insert the above cell
> > value into the newly cleared cell.
> >
> > Sub ClearRange()
> > Dim rr, r As Range
> > Set r = Range("A2:A500")
> > For Each rr In r
> > If rr.Value = "#N/A" Then
> > rr.Clear
> > rr.value = rr.offset(-1,0).value
> > End If
> > Next rr
> > End Sub
> >
> > If you're looking to fill more blank cells, something like the following
> > should work.
> >
> > Sub FillBlanks()
> > Dim rr, r As Range
> > Set r = Range("A2:A500")
> > For Each rr In r
> > If rr.Value = "" Then
> > rr.value = rr.offset(-1,0).value
> > End If
> > Next rr
> > End Sub
> >
> > Hope this helps!
> > --
> > -SA
> >
> >
> > "ryguy7272" wrote:
> >
> > > Simple problem seems to be turning into a complex problem. I want to clear
> > > all cells that show #N/A.
> > >
> > > Sub ClearRange()
> > > Dim r As Range
> > > Set r = Range("A2:A500")
> > > For Each rr In r
> > > If rr.Value = "#N/A" Then
> > > rr.Offset(0, 1).Clear
> > > End If
> > > Next
> > > End Sub
> > >
> > > As an aside, I was trying to fill all blank cells with values from above
> > > cells. It is easy to find the end of the range, but Excel seems to lose the
> > > address of the last cell in the used range once I tell it to go to the first
> > > cell in the used range (in my case it is A5)
> > >
> > > Sub FindEnd()
> > >
> > > Dim Rng As Range
> > > Cells(Rows.Count, "A").End(xlUp).Select
> > > ActiveCell.Select
> > > Rng = ActiveCell
> > >
> > > Selection.SpecialCells(xlCellTypeBlanks).Select
> > > Range("A5:Rng").Select
> > > Selection.FormulaR1C1 = "=R[-1]C"
> > >
> > > End Sub
> > >
> > >
> > > Any help with either macro would be greatly appreciated!!
> > >
> > > Regards,
> > > Ryan---
> > >
> > > --
> > > RyGuy


--

Dave Peterson
 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      23rd Jul 2008
Thanks for the code SA, and thanks, DP, for helping me to notice what I
should have noticed before I submitted my second post. Both macros are
working great!!

Regards,
Ryan---

--
RyGuy


"Dave Peterson" wrote:

> You could use:
>
> If rr.Text = "#N/A" Then
>
> or to test for any error in that cell:
>
> If iserror(rr.Value) Then
>
>
>
> ryguy7272 wrote:
> >
> > For both macros i get:
> > I get a run time error '13'
> > Type Mismatch
> >
> > Also, I need to find the used cell in Column A, because this list will
> > shrink grow each time data is pulled to create a report.
> >
> > Any other ideas?
> >
> > Thanks,
> > Ryan---
> >
> > --
> > RyGuy
> >
> > "StumpedAgain" wrote:
> >
> > > Try something like the following. I'm unsure why you did
> > > "rr.Offset(1,0).Clear" when you're trying to clear rr if rr.Value = "#N/A".
> > > Maybe I'm missing something. Also, I added a line to insert the above cell
> > > value into the newly cleared cell.
> > >
> > > Sub ClearRange()
> > > Dim rr, r As Range
> > > Set r = Range("A2:A500")
> > > For Each rr In r
> > > If rr.Value = "#N/A" Then
> > > rr.Clear
> > > rr.value = rr.offset(-1,0).value
> > > End If
> > > Next rr
> > > End Sub
> > >
> > > If you're looking to fill more blank cells, something like the following
> > > should work.
> > >
> > > Sub FillBlanks()
> > > Dim rr, r As Range
> > > Set r = Range("A2:A500")
> > > For Each rr In r
> > > If rr.Value = "" Then
> > > rr.value = rr.offset(-1,0).value
> > > End If
> > > Next rr
> > > End Sub
> > >
> > > Hope this helps!
> > > --
> > > -SA
> > >
> > >
> > > "ryguy7272" wrote:
> > >
> > > > Simple problem seems to be turning into a complex problem. I want to clear
> > > > all cells that show #N/A.
> > > >
> > > > Sub ClearRange()
> > > > Dim r As Range
> > > > Set r = Range("A2:A500")
> > > > For Each rr In r
> > > > If rr.Value = "#N/A" Then
> > > > rr.Offset(0, 1).Clear
> > > > End If
> > > > Next
> > > > End Sub
> > > >
> > > > As an aside, I was trying to fill all blank cells with values from above
> > > > cells. It is easy to find the end of the range, but Excel seems to lose the
> > > > address of the last cell in the used range once I tell it to go to the first
> > > > cell in the used range (in my case it is A5)
> > > >
> > > > Sub FindEnd()
> > > >
> > > > Dim Rng As Range
> > > > Cells(Rows.Count, "A").End(xlUp).Select
> > > > ActiveCell.Select
> > > > Rng = ActiveCell
> > > >
> > > > Selection.SpecialCells(xlCellTypeBlanks).Select
> > > > Range("A5:Rng").Select
> > > > Selection.FormulaR1C1 = "=R[-1]C"
> > > >
> > > > End Sub
> > > >
> > > >
> > > > Any help with either macro would be greatly appreciated!!
> > > >
> > > > Regards,
> > > > Ryan---
> > > >
> > > > --
> > > > RyGuy

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting up "fill in the blanks" on a document theIThombre Microsoft Word Document Management 1 2nd Sep 2008 06:08 PM
Can U have "fill in the blanks" entry on a generic, saved form? =?Utf-8?B?c2xlZXBkb2Mx?= Microsoft Word Document Management 1 28th Feb 2007 02:00 AM
Create a MS-Word "Fill-in-the-blanks" macro =?Utf-8?B?TGVhcm5pbmcgTGFkeQ==?= Microsoft Word Document Management 2 30th Dec 2006 07:55 AM
Prepare slides with a "fill in the blanks" format? =?Utf-8?B?R29sZGJ1ZzIxNzYw?= Microsoft Powerpoint 1 19th Jan 2005 03:55 AM
Logic of xlCellTypeBlanks i.e. "Blanks" period or "Blanks" in used range? Dennis Microsoft Excel Misc 8 9th Apr 2004 10:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:34 PM.