PC Review


Reply
Thread Tools Rate Thread

copy latest price from sheet1 to sheet2 using VBA

 
 
wangww
Guest
Posts: n/a
 
      23rd Mar 2008
Hi
Many record in the worksheet1,you can see below:
Date Products Price
2008-02-02 ABC 34
2008-02-03 ABC 36
2008-02-05 ABC 35

I have another sheet which named worksheet2.
Now I want to copy latest price from worksheet1 to worksheet2 by VBA.

Thanks in advance for your help.

 
Reply With Quote
 
 
 
 
cht13er
Guest
Posts: n/a
 
      23rd Mar 2008
On Mar 22, 9:21 pm, wangww <wan...@discussions.microsoft.com> wrote:
> Hi
> Many record in the worksheet1,you can see below:
> Date Products Price
> 2008-02-02 ABC 34
> 2008-02-03 ABC 36
> 2008-02-05 ABC 35
>
> I have another sheet which named worksheet2.
> Now I want to copy latest price from worksheet1 to worksheet2 by VBA.
>
> Thanks in advance for your help.


Try running this macro in a module:

Private Sub CopyNewest()

dim dtLatestDate as Date

sheets("Sheet1").activate

dtlatestdate = cells(1,1).value
cells(2,1).select

do until activecell = ""
if activecell > dtlatestdate then
dtlatestdate = activecell
end if
activecell.offset(1,0).select
loop

cells(1,1).select
do until activecell = dtlatestdate
activecells.offset(1,0).select
loop

sheets("Sheet2").Cells(1,1) = activecell.offset(0,2).value

End Sub
 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      23rd Mar 2008
Will the dates always be in chronological order per your example?

Sub findbottom_paste()
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp) _
.Offset(0, 2)
Set rng2 = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0)
rng1.Copy Destination:=rng2
End Sub

Will copy number from Price list corresponding to last entry in Date column.

Paste to first blank cell below existing data in Column A of Sheet2


Gord Dibben MS Excel MVP

On Sat, 22 Mar 2008 18:21:01 -0700, wangww <(E-Mail Removed)>
wrote:

>Hi
>Many record in the worksheet1,you can see below:
> Date Products Price
> 2008-02-02 ABC 34
> 2008-02-03 ABC 36
> 2008-02-05 ABC 35
>
>I have another sheet which named worksheet2.
>Now I want to copy latest price from worksheet1 to worksheet2 by VBA.
>
>Thanks in advance for your help.


 
Reply With Quote
 
wangww
Guest
Posts: n/a
 
      24th Mar 2008
Hi Gord Dibben
The dates always be in chronological order.

Your code is clear.
It is easy to understand.
It give me a great help.
I love you!


"Gord Dibben" wrote:

> Will the dates always be in chronological order per your example?
>
> Sub findbottom_paste()
> Dim rng1 As Range
> Dim rng2 As Range
> Set rng1 = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp) _
> .Offset(0, 2)
> Set rng2 = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) _
> .Offset(1, 0)
> rng1.Copy Destination:=rng2
> End Sub
>
> Will copy number from Price list corresponding to last entry in Date column.
>
> Paste to first blank cell below existing data in Column A of Sheet2
>
>
> Gord Dibben MS Excel MVP
>
> On Sat, 22 Mar 2008 18:21:01 -0700, wangww <(E-Mail Removed)>
> wrote:
>
> >Hi
> >Many record in the worksheet1,you can see below:
> > Date Products Price
> > 2008-02-02 ABC 34
> > 2008-02-03 ABC 36
> > 2008-02-05 ABC 35
> >
> >I have another sheet which named worksheet2.
> >Now I want to copy latest price from worksheet1 to worksheet2 by VBA.
> >
> >Thanks in advance for your help.

>
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      25th Mar 2008
Good to hear.

Thanks for the feedback.

Gord

On Mon, 24 Mar 2008 00:47:01 -0700, wangww <(E-Mail Removed)>
wrote:

>Hi Gord Dibben
>The dates always be in chronological order.
>
>Your code is clear.
>It is easy to understand.
>It give me a great help.
>I love you!
>
>
>"Gord Dibben" wrote:
>
>> Will the dates always be in chronological order per your example?
>>
>> Sub findbottom_paste()
>> Dim rng1 As Range
>> Dim rng2 As Range
>> Set rng1 = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp) _
>> .Offset(0, 2)
>> Set rng2 = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp) _
>> .Offset(1, 0)
>> rng1.Copy Destination:=rng2
>> End Sub
>>
>> Will copy number from Price list corresponding to last entry in Date column.
>>
>> Paste to first blank cell below existing data in Column A of Sheet2
>>
>>
>> Gord Dibben MS Excel MVP
>>
>> On Sat, 22 Mar 2008 18:21:01 -0700, wangww <(E-Mail Removed)>
>> wrote:
>>
>> >Hi
>> >Many record in the worksheet1,you can see below:
>> > Date Products Price
>> > 2008-02-02 ABC 34
>> > 2008-02-03 ABC 36
>> > 2008-02-05 ABC 35
>> >
>> >I have another sheet which named worksheet2.
>> >Now I want to copy latest price from worksheet1 to worksheet2 by VBA.
>> >
>> >Thanks in advance for your help.

>>
>>


 
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 data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Microsoft Excel Misc 6 27th Feb 2009 09:48 PM
Auto Copy from Sheet1 to Sheet2 ryguy7272 Microsoft Excel Programming 6 10th Jan 2008 04:23 PM
A1 Sheet2 is linked to A1 sheet1 so that user enters value(abc123) a1 sheet1 and A1 sheet2 is updated pano Microsoft Excel Programming 2 28th Oct 2007 02:32 PM
Copy some information from sheet1 to sheet2 john_liu Microsoft Excel Programming 1 26th Mar 2005 04:37 PM
Copy values from Sheet1 to Sheet2 Eintsein_mc2 Microsoft Excel Misc 1 6th Jan 2005 05:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:24 AM.