Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Need Help With Finding Date And Copying Everything To The Right OfIt?

Hey Guys,

I am stuck on a problem and would really appreciate some help with it.
I heard this is a good place to look for help. =)

I have sequential dates in Cells C3:IV3, with correlating data for
that date below it.

I need help creating a macro that would look for the first day of the
current week in the range C3:IV3 and once it is found, would copy all
cells to the right of it and paste it into Sheet2. Is this possible?

For example, for today, it would look for the date 4/13 in the range
C3:IV3. It finds that date in cell X3. It then would need to copy
cells X3:IV75 from the current sheet1 into sheet2.

I am having a hard time coming up with the logic for this. I am not an
expert user but need to get this done!! Any help would be greatly
appreciated!!!!!!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Need Help With Finding Date And Copying Everything To The Right OfIt?

Why would it copy x3:iv75? How did you get that 75??? And where would it paste
that range?

This may get you kind of started, but it only copies the

Option Explicit
Sub testme()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(3, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub

========
If you want to copy a range based on the column that matches the Sunday of the
week and through the last used row of column C, you could modify that routine
like:

Option Explicit
Sub testme2()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(LastRow, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub


Jenny Marlow wrote:

Hey Guys,

I am stuck on a problem and would really appreciate some help with it.
I heard this is a good place to look for help. =)

I have sequential dates in Cells C3:IV3, with correlating data for
that date below it.

I need help creating a macro that would look for the first day of the
current week in the range C3:IV3 and once it is found, would copy all
cells to the right of it and paste it into Sheet2. Is this possible?

For example, for today, it would look for the date 4/13 in the range
C3:IV3. It finds that date in cell X3. It then would need to copy
cells X3:IV75 from the current sheet1 into sheet2.

I am having a hard time coming up with the logic for this. I am not an
expert user but need to get this done!! Any help would be greatly
appreciated!!!!!!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Need Help With Finding Date And Copying Everything To The RightOf It?

Thanks Dave!! The one on the bottom works just great!!! Just one thing
tho, I know it's simple, but how do I paste values only? I tried

RngToCopy.Copy

Range("C3").Select

RngToPaste.PasteSpecial xlPasteValues

but that gave me an error. The code works just fine but I need to
paste the values only....

Thanks Dave, you really brightened my day by helping with this
stressful project!!

Dave Peterson wrote:
Why would it copy x3:iv75? How did you get that 75??? And where would it paste
that range?

This may get you kind of started, but it only copies the

Option Explicit
Sub testme()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(3, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub

========
If you want to copy a range based on the column that matches the Sunday of the
week and through the last used row of column C, you could modify that routine
like:

Option Explicit
Sub testme2()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(LastRow, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub


Jenny Marlow wrote:

Hey Guys,

I am stuck on a problem and would really appreciate some help with it.
I heard this is a good place to look for help. =)

I have sequential dates in Cells C3:IV3, with correlating data for
that date below it.

I need help creating a macro that would look for the first day of the
current week in the range C3:IV3 and once it is found, would copy all
cells to the right of it and paste it into Sheet2. Is this possible?

For example, for today, it would look for the date 4/13 in the range
C3:IV3. It finds that date in cell X3. It then would need to copy
cells X3:IV75 from the current sheet1 into sheet2.

I am having a hard time coming up with the logic for this. I am not an
expert user but need to get this done!! Any help would be greatly
appreciated!!!!!!


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Need Help With Finding Date And Copying Everything To The RightOf It?

I can't find my other response to this thread, but I wanted to delete
it because I figured out . I figured it out and it works just great!!
Thanks Dave for being of great help!! I made a couple changes to it
because of changed requirements but it really does the trick. Here is
my final code:

Sub testme2()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long


'first day of week (Sunday)
myDate = (Date + 1 - Weekday(Date)) - 7


With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If


Set RngToCopy
= .Range(myRng(res), .Cells(LastRow, .Columns.Count))


End With


With Sheets(2)
Set DestCell = .Range("C3")
End With

RngToCopy.Copy
Sheets(2).Range("C3").PasteSpecial _
xlPasteValues










End Sub


Thanks again Dave, you are great! =)



Dave Peterson wrote:
Why would it copy x3:iv75? How did you get that 75??? And where would it paste
that range?

This may get you kind of started, but it only copies the

Option Explicit
Sub testme()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(3, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub

========
If you want to copy a range based on the column that matches the Sunday of the
week and through the last used row of column C, you could modify that routine
like:

Option Explicit
Sub testme2()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(LastRow, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub


Jenny Marlow wrote:

Hey Guys,

I am stuck on a problem and would really appreciate some help with it.
I heard this is a good place to look for help. =)

I have sequential dates in Cells C3:IV3, with correlating data for
that date below it.

I need help creating a macro that would look for the first day of the
current week in the range C3:IV3 and once it is found, would copy all
cells to the right of it and paste it into Sheet2. Is this possible?

For example, for today, it would look for the date 4/13 in the range
C3:IV3. It finds that date in cell X3. It then would need to copy
cells X3:IV75 from the current sheet1 into sheet2.

I am having a hard time coming up with the logic for this. I am not an
expert user but need to get this done!! Any help would be greatly
appreciated!!!!!!


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Need Help With Finding Date And Copying Everything To The Right OfIt?

You could have used:

With Sheets(2)
Set DestCell = .Range("C3")
End With

RngToCopy.Copy
DestCell.PasteSpecial paste:=xlPasteValues

I'm not sure I'd use Sheets(2). This means it'll be the second sheet from the
left. If that name doesn't change (and you know it), you could use:

With Worksheets("Sheet9999")

Jenny Marlow wrote:

I can't find my other response to this thread, but I wanted to delete
it because I figured out . I figured it out and it works just great!!
Thanks Dave for being of great help!! I made a couple changes to it
because of changed requirements but it really does the trick. Here is
my final code:

Sub testme2()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long

'first day of week (Sunday)
myDate = (Date + 1 - Weekday(Date)) - 7

With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy
= .Range(myRng(res), .Cells(LastRow, .Columns.Count))

End With

With Sheets(2)
Set DestCell = .Range("C3")
End With

RngToCopy.Copy
Sheets(2).Range("C3").PasteSpecial _
xlPasteValues

End Sub

Thanks again Dave, you are great! =)

Dave Peterson wrote:
Why would it copy x3:iv75? How did you get that 75??? And where would it paste
that range?

This may get you kind of started, but it only copies the

Option Explicit
Sub testme()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(3, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub

========
If you want to copy a range based on the column that matches the Sunday of the
week and through the last used row of column C, you could modify that routine
like:

Option Explicit
Sub testme2()
Dim myDate As Date
Dim res As Variant
Dim myRng As Range
Dim RngToCopy As Range
Dim DestCell As Range
Dim LastRow As Long

'first day of week (Sunday)
myDate = Date + 1 - Weekday(Date)

With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRng = .Range("c3:iv3")
res = Application.Match(CLng(myDate), myRng, 0)
If IsError(res) Then
MsgBox "Date not found!"
Exit Sub
End If

Set RngToCopy = .Range(myRng(res), .Cells(LastRow, .Columns.Count))

End With

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

RngToCopy.Copy _
Destination:=DestCell

End Sub


Jenny Marlow wrote:

Hey Guys,

I am stuck on a problem and would really appreciate some help with it.
I heard this is a good place to look for help. =)

I have sequential dates in Cells C3:IV3, with correlating data for
that date below it.

I need help creating a macro that would look for the first day of the
current week in the range C3:IV3 and once it is found, would copy all
cells to the right of it and paste it into Sheet2. Is this possible?

For example, for today, it would look for the date 4/13 in the range
C3:IV3. It finds that date in cell X3. It then would need to copy
cells X3:IV75 from the current sheet1 into sheet2.

I am having a hard time coming up with the logic for this. I am not an
expert user but need to get this done!! Any help would be greatly
appreciated!!!!!!


--

Dave Peterson


--

Dave Peterson
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
Finding a value and copying it to another cell Noncentz303 Excel Worksheet Functions 2 May 2nd 07 07:05 PM
Finding a date range from given date Sarah (OGI) Excel Worksheet Functions 1 April 18th 07 03:08 PM
finding a date/time in a list that is closest to an existing date/ Jamie Excel Discussion (Misc queries) 1 May 27th 06 08:54 PM
Finding the Monday date based on a different date in same week dandiehl Excel Worksheet Functions 4 April 11th 06 06:03 PM
finding duplicate then copying macro.. Michael A Excel Discussion (Misc queries) 5 March 8th 05 03:26 AM


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