PC Review


Reply
Thread Tools Rate Thread

Copy Non-Colored Cells to a New Sheet

 
 
ryguy7272
Guest
Posts: n/a
 
      11th Jun 2008
I tried the following macro to copy/paste non-colored cells to a sheet called
‘Copy If Non Color’. For some reason, all cells are copied to that sheet,
not just the non-colored cells. What am I doing wrong?

Sub noncolorcopier()
Dim w As Long
y = 1
Set z = ActiveSheet.UsedRange
nLastRow = z.Rows.Count + z.Row - 1
For w = 1 To nLastRow
If is_it_non_red(w) Then
Set rc = Cells(w, 1).EntireRow
Set rd = Sheets("Copy If Non Color").Cells(y, 1)
rc.Copy rd
y = y + 1
End If
Next


End Sub


Function is_it_non_red(w As Long) As Boolean
is_it_non_red = False
For x = 1 To Columns.Count
If Cells(w, x).Interior.ColorIndex = xlNone Or Cells(w,
x).Interior.ColorIndex = xlWhite Then
is_it_non_red = True
Exit Function
End If
Next
End Function


Regards,
Ryan---


--
RyGuy
 
Reply With Quote
 
 
 
 
SteveM
Guest
Posts: n/a
 
      11th Jun 2008
On Jun 11, 3:09 pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
wrote:
> I tried the following macro to copy/paste non-colored cells to a sheet called
> ‘Copy If Non Color’. For some reason, all cells are copied to that sheet,
> not just the non-colored cells. What am I doing wrong?
>
> Sub noncolorcopier()
> Dim w As Long
> y = 1
> Set z = ActiveSheet.UsedRange
> nLastRow = z.Rows.Count + z.Row - 1
> For w = 1 To nLastRow
> If is_it_non_red(w) Then
> Set rc = Cells(w, 1).EntireRow
> Set rd = Sheets("Copy If Non Color").Cells(y, 1)
> rc.Copy rd
> y = y + 1
> End If
> Next
>
> End Sub
>
> Function is_it_non_red(w As Long) As Boolean
> is_it_non_red = False
> For x = 1 To Columns.Count
> If Cells(w, x).Interior.ColorIndex = xlNone Or Cells(w,
> x).Interior.ColorIndex = xlWhite Then
> is_it_non_red = True
> Exit Function
> End If
> Next
> End Function
>
> Regards,
> Ryan---
>
> --
> RyGuy


RyGuy,

I may be a better idea to zotz out the values on the back end after
you have pasted (with formats):

Sub ZotzNoColors()
Dim cell As Range
Dim dataRange As Range

Set dataRange = Range("Whatever")
For Each cell In dataRange
If cell.Interior.ColorIndex = xlNone Then
cell = ""
End If
End Sub
 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      11th Jun 2008
VERY interesting. I never thought of that before. How would I apply this
technique to the whole row? For instance, if there is a colored cell
somewhere in the row, make the entire row = "", or just delete the row, or
something along those lines.

Code Below (not working):
Sub ZotzNoColors()
Dim i As Long
Dim cell As Range
Dim dataRange As Range

Set dataRange = Range("Whatever")
For Each cell In dataRange
If cell.Interior.ColorIndex <> xlNone Then
Set rc = Cells(i, 1).EntireRow
rc = ""
End If
Next cell
End Sub


--
RyGuy


"SteveM" wrote:

> On Jun 11, 3:09 pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
> wrote:
> > I tried the following macro to copy/paste non-colored cells to a sheet called
> > ‘Copy If Non Color’. For some reason, all cells are copied to that sheet,
> > not just the non-colored cells. What am I doing wrong?
> >
> > Sub noncolorcopier()
> > Dim w As Long
> > y = 1
> > Set z = ActiveSheet.UsedRange
> > nLastRow = z.Rows.Count + z.Row - 1
> > For w = 1 To nLastRow
> > If is_it_non_red(w) Then
> > Set rc = Cells(w, 1).EntireRow
> > Set rd = Sheets("Copy If Non Color").Cells(y, 1)
> > rc.Copy rd
> > y = y + 1
> > End If
> > Next
> >
> > End Sub
> >
> > Function is_it_non_red(w As Long) As Boolean
> > is_it_non_red = False
> > For x = 1 To Columns.Count
> > If Cells(w, x).Interior.ColorIndex = xlNone Or Cells(w,
> > x).Interior.ColorIndex = xlWhite Then
> > is_it_non_red = True
> > Exit Function
> > End If
> > Next
> > End Function
> >
> > Regards,
> > Ryan---
> >
> > --
> > RyGuy

>
> RyGuy,
>
> I may be a better idea to zotz out the values on the back end after
> you have pasted (with formats):
>
> Sub ZotzNoColors()
> Dim cell As Range
> Dim dataRange As Range
>
> Set dataRange = Range("Whatever")
> For Each cell In dataRange
> If cell.Interior.ColorIndex = xlNone Then
> cell = ""
> End If
> End Sub
>

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      12th Jun 2008
Oh, just got it. The code is like this:
Sub noncolorcopier()
Dim w As Long
y = 1
Set z = ActiveSheet.UsedRange
nLastRow = z.Rows.Count + z.Row - 1
For w = 1 To nLastRow
If is_it_non_red(w) Then
Set rc = Cells(w, 1).EntireRow
Set rd = Sheets("Copy If Non Color").Cells(y, 1)
rc.Copy rd
y = y + 1
End If
Next


End Sub


Function is_it_non_red(w As Long) As Boolean
is_it_non_red = True
For x = 1 To Columns.Count
If Cells(w, x).Interior.ColorIndex <> xlNone Then
is_it_non_red = False
Exit Function
End If
Next
End Function

I just flipped these:
is_it_non_red = False
is_it_non_red = True

To these:
is_it_non_red = True
is_it_non_red = False


Hope this helps others.
Ryan---

--
RyGuy


"ryguy7272" wrote:

> VERY interesting. I never thought of that before. How would I apply this
> technique to the whole row? For instance, if there is a colored cell
> somewhere in the row, make the entire row = "", or just delete the row, or
> something along those lines.
>
> Code Below (not working):
> Sub ZotzNoColors()
> Dim i As Long
> Dim cell As Range
> Dim dataRange As Range
>
> Set dataRange = Range("Whatever")
> For Each cell In dataRange
> If cell.Interior.ColorIndex <> xlNone Then
> Set rc = Cells(i, 1).EntireRow
> rc = ""
> End If
> Next cell
> End Sub
>
>
> --
> RyGuy
>
>
> "SteveM" wrote:
>
> > On Jun 11, 3:09 pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
> > wrote:
> > > I tried the following macro to copy/paste non-colored cells to a sheet called
> > > ‘Copy If Non Color’. For some reason, all cells are copied to that sheet,
> > > not just the non-colored cells. What am I doing wrong?
> > >
> > > Sub noncolorcopier()
> > > Dim w As Long
> > > y = 1
> > > Set z = ActiveSheet.UsedRange
> > > nLastRow = z.Rows.Count + z.Row - 1
> > > For w = 1 To nLastRow
> > > If is_it_non_red(w) Then
> > > Set rc = Cells(w, 1).EntireRow
> > > Set rd = Sheets("Copy If Non Color").Cells(y, 1)
> > > rc.Copy rd
> > > y = y + 1
> > > End If
> > > Next
> > >
> > > End Sub
> > >
> > > Function is_it_non_red(w As Long) As Boolean
> > > is_it_non_red = False
> > > For x = 1 To Columns.Count
> > > If Cells(w, x).Interior.ColorIndex = xlNone Or Cells(w,
> > > x).Interior.ColorIndex = xlWhite Then
> > > is_it_non_red = True
> > > Exit Function
> > > End If
> > > Next
> > > End Function
> > >
> > > Regards,
> > > Ryan---
> > >
> > > --
> > > RyGuy

> >
> > RyGuy,
> >
> > I may be a better idea to zotz out the values on the back end after
> > you have pasted (with formats):
> >
> > Sub ZotzNoColors()
> > Dim cell As Range
> > Dim dataRange As Range
> >
> > Set dataRange = Range("Whatever")
> > For Each cell In dataRange
> > If cell.Interior.ColorIndex = xlNone Then
> > cell = ""
> > End If
> > End Sub
> >

 
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
Copy Sheet to new Sheet and clear cells on original sheets Boiler-Todd Microsoft Excel Misc 7 23rd Sep 2009 10:02 PM
RE: Copy sheet cells into differnt workbook/sheet, How? Shane Devenshire Microsoft Excel Misc 1 2nd Jun 2009 11:16 PM
Copy sheet cells into differnt workbook/sheet, How? IVLUTA Microsoft Excel Misc 0 2nd Jun 2009 10:56 PM
Cell right next to colored cells is automatically colored on entering a value Johan De Schutter Microsoft Excel Misc 6 12th Sep 2003 05:31 PM
Cell right next to colored cells is automatically colored on entering a value Johan De Schutter Microsoft Excel Programming 6 12th Sep 2003 05:31 PM


Features
 

Advertising
 

Newsgroups
 


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