Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Copy Value to a Row with Date that is specified Query


I have some values in B1 through to B4. These relate to costs for 4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different worksheet
within the same file that will look for the relevant date that I have listed
in Column A on this second worksheet. I want to Transpose this Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Value to a Row with Date that is specified Query

Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...

I have some values in B1 through to B4. These relate to costs for 4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different

worksheet
within the same file that will look for the relevant date that I have

listed
in Column A on this second worksheet. I want to Transpose this Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Copy Value to a Row with Date that is specified Query

Thanks Tom


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...

I have some values in B1 through to B4. These relate to costs for 4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different

worksheet
within the same file that will look for the relevant date that I have

listed
in Column A on this second worksheet. I want to Transpose this Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Copy Value to a Row with Date that is specified Query

Tom

How is it possible tocopy values say in C1:C4 in to a different worksheet
say Sheet3 within the same code.

I tried just replicating the code fora new sheet but it doesn't work for me.
Don't know what Next, End If statements I need and don't

Thanks


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...

I have some values in B1 through to B4. These relate to costs for 4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different

worksheet
within the same file that will look for the relevant date that I have

listed
in Column A on this second worksheet. I want to Transpose this Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Value to a Row with Date that is specified Query

Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet3")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("C1:C4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...
Tom

How is it possible tocopy values say in C1:C4 in to a different worksheet
say Sheet3 within the same code.

I tried just replicating the code fora new sheet but it doesn't work for

me.
Don't know what Next, End If statements I need and don't

Thanks


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...

I have some values in B1 through to B4. These relate to costs for 4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different

worksheet
within the same file that will look for the relevant date that I have

listed
in Column A on this second worksheet. I want to Transpose this Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Copy Value to a Row with Date that is specified Query

Thanks for the reply Tom I know is probably a very basic question but how
can I include both Subs within the one sub so that all run under the same
macro?


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet3")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("C1:C4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...
Tom

How is it possible tocopy values say in C1:C4 in to a different

worksheet
say Sheet3 within the same code.

I tried just replicating the code fora new sheet but it doesn't work for

me.
Don't know what Next, End If statements I need and don't

Thanks


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...

I have some values in B1 through to B4. These relate to costs for 4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different
worksheet
within the same file that will look for the relevant date that I

have
listed
in Column A on this second worksheet. I want to Transpose this Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Value to a Row with Date that is specified Query

One way would be to name the second one as Tester3 and call it from the
first one:

Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
tester3
End Sub

Sub Tester3()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet3")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("C1:C4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

That is the simple solution. I would assume that if more was know about
what is being done, that a lot of the code wouldn't have to be repeated.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Thanks for the reply Tom I know is probably a very basic question but how
can I include both Subs within the one sub so that all run under the same
macro?


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet3")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("C1:C4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...
Tom

How is it possible tocopy values say in C1:C4 in to a different

worksheet
say Sheet3 within the same code.

I tried just replicating the code fora new sheet but it doesn't work

for
me.
Don't know what Next, End If statements I need and don't

Thanks


"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim sh As Worksheet
Dim rng As Range, rng1 As Range
Dim cell As Range, dt As Date
Set sh = Worksheets("Costs")
dt = sh.Range("A1").Value
With Worksheets("Sheet2")
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With
For Each cell In rng
If cell.Value2 = CLng(dt) Then
Set rng1 = cell
Exit For
End If
Next
If rng1 Is Nothing Then
MsgBox Format(dt, "mmm dd, yyyy") & "was not found"
Exit Sub
End If
sh.Range("B1:B4").Copy
rng1.Offset(0, 1).PasteSpecial Transpose:=True
End Sub

--
Regards,
Tom Ogilvy


"John" wrote in message
...

I have some values in B1 through to B4. These relate to costs for

4
locations. In column A1 is the week that these costs relate to.

How can I write code to copy and paste these values to a different
worksheet
within the same file that will look for the relevant date that I

have
listed
in Column A on this second worksheet. I want to Transpose this

Paste
function as my locations are within column B through to column E

Hoe that all makes sense.

Thanks












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
Macro copy query One carla 7 Excel Discussion (Misc queries) 0 July 31st 08 10:55 AM
Macro Copy Workbook Query carla 7 Excel Discussion (Misc queries) 2 July 31st 08 12:58 AM
Find & Copy Data query bbibib Excel Discussion (Misc queries) 3 February 9th 06 06:35 PM
Query, copy & paste ThalesNate Excel Discussion (Misc queries) 9 February 3rd 06 02:24 AM
How do I enter a date range ie -7 from current date in MS QUERY notsmartenough Excel Discussion (Misc queries) 1 November 11th 05 10:17 PM


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