Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default select only certain cells in a columns

How would I write an if statement to select all the cells in a column that are marked true, and then move those true rows somewhere else?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default select only certain cells in a columns

Dim rng as Range, cell as Range, rng1 as Range
set rng = Range(cells(1,"C"),Cells(rows.count,"C").End(xlup) )
set rng1 = nothing
for each cell in rng
if cell.value = "True" then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = union(rng1,cell)
end if
Next
Next
if not rng1 is nothing then
rng1.entirerow.copy Destination:=worksheets("Sheet2").Range("A1")
rng1.EntireRow.delete
End if

code is untested.
--
regards,
Tom Ogilvy

"desperate" wrote in message
...
How would I write an if statement to select all the cells in a column that

are marked true, and then move those true rows somewhere else?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default select only certain cells in a columns

Here's a solution that takes the rows from one sheet and moves to another,
with no looping

Dim oldSh As Worksheet
With ActiveSheet
Set oldSh = ActiveSheet
.Range("D1").EntireRow.Insert
.Columns("D:D").AutoFilter Field:=1, Criteria1:="TRUE"
.Cells.SpecialCells(xlCellTypeVisible).Copy
End With
Worksheets("Sheet2").Activate
Range("A1").Select
ActiveSheet.Paste
oldSh.Activate
With ActiveSheet
.Cells.SpecialCells(xlCellTypeVisible).EntireRow.D elete
.Rows("1:1").Delete Shift:=xlUp
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"desperate" wrote in message
...
How would I write an if statement to select all the cells in a column that

are marked true, and then move those true rows somewhere else?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default select only certain cells in a columns

Thank you. This coding helps very much, but I don't want to cut the rows from the first sheet, I want to just copy them onto the second sheet. How would I do that?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default select only certain cells in a columns

Hi
just delete the last line:
rng1.EntireRow.delete

--
Regards
Frank Kabel
Frankfurt, Germany

desperate wrote:
Thank you. This coding helps very much, but I don't want to cut the
rows from the first sheet, I want to just copy them onto the second
sheet. How would I do that?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default select only certain cells in a columns

You said "move", so if you don't want to retain the values in the original
and you don't want to delete, then you must want to clear:

Dim rng as Range, cell as Range, rng1 as Range
set rng = Range(cells(1,"C"),Cells(rows.count,"C").End(xlup) )
set rng1 = nothing
for each cell in rng
if cell.value = "True" then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = union(rng1,cell)
end if
Next
Next
if not rng1 is nothing then
rng1.entirerow.copy Destination:=worksheets("Sheet2").Range("A1")
rng1.EntireRow.clearContents
End if

--
Regards,
Tom Ogilvy


"desperate" wrote in message
...
Thank you. This coding helps very much, but I don't want to cut the rows

from the first sheet, I want to just copy them onto the second sheet. How
would I do that?


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
Up down arrow keys do not select cells if select locked cells unch roandrob Excel Discussion (Misc queries) 3 May 18th 09 12:48 AM
Using formulas to select cells (Ex: Select every nth cell in a col Lakeview Photographic Services Excel Discussion (Misc queries) 2 March 15th 07 02:17 PM
How do I input numbers used to select cells in several columns BC2233 Excel Discussion (Misc queries) 3 February 16th 06 05:35 PM
how do you "select locked cells" w/o "select unlocked cells"? princejohnpaulfin Excel Discussion (Misc queries) 3 July 16th 05 03:53 AM
How do you select two cells in different rows and columns with ou. M.G Excel Discussion (Misc queries) 3 December 17th 04 11:39 PM


All times are GMT +1. The time now is 11:34 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"