Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Conditional find and copy to different worksheet.

Hi, I am a new in VBA and I am wondering whether someone can help me. I would
like to create a macro which will search for string value in a worksheet
€œdata€ column €œA€ and if it finds the match it will take the integer value
from worksheet €œData€ column €œB€ and copy it to another worksheet €œNames€
column €œB2€ and additionally make sum of the values as they are always a
numbers.
A B
Peter 3
Martin 4
Albert 5
Wendy 8
Danka 77
Wendy 8
Wendy 9

Many thanks,
Peter.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Conditional find and copy to different worksheet.

Change the sheet names or index number to suit. You didn't specify where to
put the sum of the copied data so I put it in sheet2, col C, Offset 1 row
from the last entry in col B. Alter as needed.

Sub getTotal()
Dim lr As Long, lr2 As Long
Dim c As Range
'Change Sheet name or index to suit.
lr = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
Nm = InputBox("Enter Name to Match", "NAME")
For Each c In Sheets(1).Range("A2:A" & lr)
If c.Value = Nm Then
c.Offset(0, 1).Copy Sheets(2).Range("B" & _
Sheets(2).Range("B65336").End(xlUp).Row + 1)
End If
Next
lr2 = Sheets(2).Range("B65336").End(xlUp).Row
Sheets(2).Range("C" & lr2 + 1) = _
WorksheetFunction.Sum(Sheets(2).Range("B2:B" & lr))
End Sub


"Peter Gasparik" wrote:

Hi, I am a new in VBA and I am wondering whether someone can help me. I would
like to create a macro which will search for string value in a worksheet
€œdata€ column €œA€ and if it finds the match it will take the integer value
from worksheet €œData€ column €œB€ and copy it to another worksheet €œNames€
column €œB2€ and additionally make sum of the values as they are always a
numbers.
A B
Peter 3
Martin 4
Albert 5
Wendy 8
Danka 77
Wendy 8
Wendy 9

Many thanks,
Peter.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Conditional find and copy to different worksheet.

This modifies the previous code to basically make the InputBox entry case
insensitive.

Sub getTotal()
Dim lr As Long, lr2 As Long
Dim c As Range
'Change Sheet name or index to suit.
lr = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
Nm = InputBox("Enter Name to Match", "NAME")
For Each c In Sheets(1).Range("A2:A" & lr)
If LCase(c.Value) = LCase(Nm) Then
c.Offset(0, 1).Copy Sheets(2).Range("B" & _
Sheets(2).Range("B65336").End(xlUp).Row + 1)
End If
Next
lr2 = Sheets(2).Range("B65336").End(xlUp).Row
Sheets(2).Range("C" & lr2 + 1) = _
WorksheetFunction.Sum(Sheets(2).Range("B2:B" & lr))
End Sub






"Peter Gasparik" wrote:

Hi, I am a new in VBA and I am wondering whether someone can help me. I would
like to create a macro which will search for string value in a worksheet
€œdata€ column €œA€ and if it finds the match it will take the integer value
from worksheet €œData€ column €œB€ and copy it to another worksheet €œNames€
column €œB2€ and additionally make sum of the values as they are always a
numbers.
A B
Peter 3
Martin 4
Albert 5
Wendy 8
Danka 77
Wendy 8
Wendy 9

Many thanks,
Peter.

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
Conditional Copy from one worksheet to another John Duich Excel Worksheet Functions 1 April 19th 10 02:10 AM
Find and copy duplicates to new worksheet Del_F Excel Programming 5 October 22nd 07 06:55 PM
can i freeze conditional formating to copy to another worksheet Chris Lane Excel Discussion (Misc queries) 1 October 12th 05 06:53 PM
why can't excel do a simple find and copy row from a worksheet to. rasman Excel Worksheet Functions 2 December 28th 04 05:49 PM
simple conditional find, copy and paste lothario[_56_] Excel Programming 2 December 1st 03 08:34 AM


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