#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 91
Default Data moving 2

I have following code:
Sub climate()
Dim x As Long, y As Long
x = Range("X" & Rows.Count).End(xlUp).Row
y = InputBox("enter the row number to paste")
Range("A2:BK2" & x).Copy
Range("A" & y).PasteSpecial
MsgBox "Updated"
End Sub

I want to cut data of range(A2:BK2 to end row related) and then paste to row
number which determine in Box. when i run above code on some of sheets, error
message appear(Run Time error 1004). please note that, this code with cut
command not run, only with copy command.

any help will be greatly appreciated.
climate
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 342
Default Data moving 2

I made a few notes in your code:

Dim x As Long, y As Long
'One character variables are risky.
x = Range("X" & Rows.Count).End(xlUp).Row
'Finds the last used row in column X
y = InputBox("enter the row number to paste")
Range("A2:BK2" & x).Copy
'Invalid - if x is 40 then the range would be 240 _
Remove the 2 after BK.
Range("A" & y).PasteSpecial
'Why PasteSpecial without telling what is special
'Also, you cannot PasteSpecial cell that were Cut.
MsgBox "Updated"
End Sub


Then I wrote and tested the following. It should work better.

Sub climate2()

Dim xLng As Long, yLng As Long
xLng = Range("X" & Rows.Count).End(xlUp).Row
yLng = InputBox("enter the row number to paste to:")
Range("A2:BK" & xLng).Cut 'or Cut (Can't PasteSpecial Cut cells)
Range("A" & yLng).PasteSpecial Paste:=xlPasteValues 'Or just Paste
Application.CutCopyMode = False
Range("A1").Select
MsgBox "Updated"

End Sub

Good luck,

Tom

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 342
Default Data moving 2

Woops, I forgot to change cut back to copy. Use this:

Sub climate2()

Dim xLng As Long, yLng As Long
xLng = Range("X" & Rows.Count).End(xlUp).Row
yLng = InputBox("enter the row number to paste")
Range("A2:BK" & xLng).Copy 'or Cut (Can't PasteSpecial Cut cells)
Range("A" & yLng).PasteSpecial Paste:=xlPasteValues 'Or just Paste
Application.CutCopyMode = False
Range("A1").Select
MsgBox "Updated"

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 91
Default Data moving 2

Hi tom
Thank you
I tested your code, first problem (run time error)is solved, but desired
range dosen't cut, and overlap to prior data. i need to move desired range
and paste to new position based on row number in Box.

"tompl" wrote:

Woops, I forgot to change cut back to copy. Use this:

Sub climate2()

Dim xLng As Long, yLng As Long
xLng = Range("X" & Rows.Count).End(xlUp).Row
yLng = InputBox("enter the row number to paste")
Range("A2:BK" & xLng).Copy 'or Cut (Can't PasteSpecial Cut cells)
Range("A" & yLng).PasteSpecial Paste:=xlPasteValues 'Or just Paste
Application.CutCopyMode = False
Range("A1").Select
MsgBox "Updated"

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 342
Default Data moving 2

I did not fully understand your question before, but this should work for you:

Sub climate3()

Dim xLng As Long, yLng As Long
xLng = Range("X" & Rows.Count).End(xlUp).Row
yLng = InputBox("enter the row number to paste")
Range("A2:BK" & xLng).Cut Range("A" & yLng)
Application.CutCopyMode = False
Range("A1").Select
MsgBox "Updated"

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 91
Default Data moving 2

Hi
Thank you very much, your code work's correctly.

regards

"tompl" wrote:

I did not fully understand your question before, but this should work for you:

Sub climate3()

Dim xLng As Long, yLng As Long
xLng = Range("X" & Rows.Count).End(xlUp).Row
yLng = InputBox("enter the row number to paste")
Range("A2:BK" & xLng).Cut Range("A" & yLng)
Application.CutCopyMode = False
Range("A1").Select
MsgBox "Updated"

End Sub

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Data moving 2

It would have helped if along with telling us what the error message was if
you also told us what line it occurred on (which line did the debugger
highlight). I have no idea if the following is the root of your problem or
not, but this line is not doing what you think...

Range("A2:BK2" & x).Copy

That is not how you construct the range you want. The "2" at the end of
"BK2" should not be there. For example, if "x" evaluates to, say, 999, then
your range becomes A2:BK2999, not A2:BK999... that is some 2000 rows below
the last piece of data in Column X. I believe you want this instead...

Range("A2:BK" & x).Copy

--
Rick (MVP - Excel)



"climate" wrote in message
...
I have following code:
Sub climate()
Dim x As Long, y As Long
x = Range("X" & Rows.Count).End(xlUp).Row
y = InputBox("enter the row number to paste")
Range("A2:BK2" & x).Copy
Range("A" & y).PasteSpecial
MsgBox "Updated"
End Sub

I want to cut data of range(A2:BK2 to end row related) and then paste to
row
number which determine in Box. when i run above code on some of sheets,
error
message appear(Run Time error 1004). please note that, this code with cut
command not run, only with copy command.

any help will be greatly appreciated.
climate


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 91
Default Data moving 2

Hi
Thank's Rick, your discussion is right.

regards

"Rick Rothstein" wrote:

It would have helped if along with telling us what the error message was if
you also told us what line it occurred on (which line did the debugger
highlight). I have no idea if the following is the root of your problem or
not, but this line is not doing what you think...

Range("A2:BK2" & x).Copy

That is not how you construct the range you want. The "2" at the end of
"BK2" should not be there. For example, if "x" evaluates to, say, 999, then
your range becomes A2:BK2999, not A2:BK999... that is some 2000 rows below
the last piece of data in Column X. I believe you want this instead...

Range("A2:BK" & x).Copy

--
Rick (MVP - Excel)



"climate" wrote in message
...
I have following code:
Sub climate()
Dim x As Long, y As Long
x = Range("X" & Rows.Count).End(xlUp).Row
y = InputBox("enter the row number to paste")
Range("A2:BK2" & x).Copy
Range("A" & y).PasteSpecial
MsgBox "Updated"
End Sub

I want to cut data of range(A2:BK2 to end row related) and then paste to
row
number which determine in Box. when i run above code on some of sheets,
error
message appear(Run Time error 1004). please note that, this code with cut
command not run, only with copy command.

any help will be greatly appreciated.
climate


.

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
Moving a line chart data point revises data table value in Excel ' Ed Smith Charts and Charting in Excel 2 November 16th 12 01:03 PM
Moving Data between sheets in the same workbook and moving data between Workbooks. Alison Brown Excel Worksheet Functions 0 February 10th 09 01:03 AM
Moving data from one worksheet to another whilst removing the data Dobbin0_4[_2_] Excel Discussion (Misc queries) 2 September 17th 08 03:31 PM
moving data to non autofarmatted book changes data- Why? Josh Excel Discussion (Misc queries) 3 March 10th 06 09:16 PM
moving data in excel without deleting existing data jigna Excel Discussion (Misc queries) 1 January 30th 05 11:35 AM


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