PC Review


Reply
Thread Tools Rate Thread

Conditional find and copy to different worksheet.

 
 
Peter Gasparik
Guest
Posts: n/a
 
      23rd Nov 2008
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 With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      24th Nov 2008
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.

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      24th Nov 2008
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 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
Conditional Copy from one worksheet to another John Duich Microsoft Excel Worksheet Functions 1 19th Apr 2010 02:10 AM
Find in another worksheet and copy to original worksheet. Reinie Microsoft Excel Programming 0 5th Aug 2009 09:30 PM
Copy conditional format using formula to entire worksheet DOOGIE Microsoft Excel Programming 1 25th Sep 2008 02:08 PM
...Can I copy the Conditional Formatting I have on Worksheet # 1 t =?Utf-8?B?RHIuIERhcnJlbGw=?= Microsoft Excel Crashes 1 15th Dec 2005 09:40 PM
can i freeze conditional formating to copy to another worksheet =?Utf-8?B?Q2hyaXMgTGFuZQ==?= Microsoft Excel Misc 1 12th Oct 2005 06:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:33 AM.