Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Copy cells to different sheet if value found

I have an Excel 2010 workbook with multiple worksheets.

Worksheet 'one' has column B holding values such as ',1,12,20,'
(starting at row 2) with adjacent cells in column C holding textual
comments relating to the entries in column B.

I need to search through column B and find the first cell holding ',1,'
and then copy the adjacent cell in column C to column D in worksheet
'two'. The search then needs to continue to find the next occurrence of
',1,' in B and copy the corresponding cell in column C to the next row
in column D of worksheet 'two'.

Some of the cells in column B of worksheet 'one' do not hold ',1,' so I
would prefer it if they did not provoke blank rows in worksheet 'two'.

Any help would be gratefully received!

TIA

--
F

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy cells to different sheet if value found

Hi,

Am Wed, 24 Apr 2013 20:45:20 +0100 schrieb F:

I need to search through column B and find the first cell holding ',1,'
and then copy the adjacent cell in column C to column D in worksheet
'two'. The search then needs to continue to find the next occurrence of
',1,' in B and copy the corresponding cell in column C to the next row
in column D of worksheet 'two'.


try (modify to suit):

Sub myCopy()
Dim LRow As Long
Dim rngC As Range
Dim i As Long

i = 2
With Sheets("Sheet1")
LRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For Each rngC In .Range("B2:B" & LRow)
If InStr(rngC, ",1,") 0 Then
Sheets("Sheet2").Cells(i, 4) = rngC.Offset(0, 1)
i = i + 1
End If
Next
End With
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Copy cells to different sheet if value found

On 24/04/2013 21:19 Claus Busch wrote:

Hi,

Am Wed, 24 Apr 2013 20:45:20 +0100 schrieb F:

I need to search through column B and find the first cell holding ',1,'
and then copy the adjacent cell in column C to column D in worksheet
'two'. The search then needs to continue to find the next occurrence of
',1,' in B and copy the corresponding cell in column C to the next row
in column D of worksheet 'two'.


try (modify to suit):

Sub myCopy()
Dim LRow As Long
Dim rngC As Range
Dim i As Long

i = 2
With Sheets("Sheet1")
LRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For Each rngC In .Range("B2:B" & LRow)
If InStr(rngC, ",1,") 0 Then
Sheets("Sheet2").Cells(i, 4) = rngC.Offset(0, 1)
i = i + 1
End If
Next
End With
End Sub


Regards
Claus Busch


Amazing, and such a speedy response. Thank you!!

Can I ask for an enhancement? Is it possible to avoid copying the cell
in column C if it is blank?

--
F



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy cells to different sheet if value found

Hi,

Am Wed, 24 Apr 2013 21:35:39 +0100 schrieb F:

Can I ask for an enhancement? Is it possible to avoid copying the cell
in column C if it is blank?


change the IF-statement:

If InStr(rngC, ",1,") 0 And Len(rngC.Offset(0, 1)) 0 Then
Sheets("Sheet2").Cells(i, 4) = rngC.Offset(0, 1)
i = i + 1
End If


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Copy cells to different sheet if value found

On 24/04/2013 21:44 Claus Busch wrote:

Hi,

Am Wed, 24 Apr 2013 21:35:39 +0100 schrieb F:

Can I ask for an enhancement? Is it possible to avoid copying the cell
in column C if it is blank?


change the IF-statement:

If InStr(rngC, ",1,") 0 And Len(rngC.Offset(0, 1)) 0 Then
Sheets("Sheet2").Cells(i, 4) = rngC.Offset(0, 1)
i = i + 1
End If


Regards
Claus Busch


Perfect. Thank you again: much appreciated!

--
F



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
Search for values in a sheet and copy found records one after theother in another sheet AndreasHermle Excel Programming 12 June 17th 11 08:12 PM
copy and past cells found by SUMPRODUCT Tromal Excel Worksheet Functions 2 May 30th 10 02:03 PM
Lookup and copy cells if match found Kcope8302 Excel Programming 2 September 16th 09 02:37 PM
Copy Cells Found S1L1Y1 Excel Discussion (Misc queries) 2 May 19th 08 05:31 PM
copy, paste into a 'found' row on another sheet problem...... [email protected] Excel Programming 7 November 26th 06 06:32 PM


All times are GMT +1. The time now is 11:49 PM.

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"