ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   difficult question (https://www.excelbanter.com/excel-discussion-misc-queries/137433-difficult-question.html)

Wu

difficult question
 
I want to write a marco that to copy few specified rows from sheet 1 to sheet
2:
.................................................. .................................................. ....
R=Inputbox("pls input the first row number")
R1=inputbox("pls input the last row number")

Rows(R:R1).Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste

.................................................. .................................................. ......

But, the above macro is not work at "Rows(R:R1).Select", I would like to use
inputbox to enter specified number of row to copy from sheet1 to sheet2. How
to do that???


JE McGimpsey

difficult question
 
One way:

Dim vFirst As Variant
Dim vLast As Variant

Do
vFirst = Application.InputBox( _
Prompt:="Please input the first row number", _
Title:="Copy Rows", _
Default:=1, _
Type:=1)
If vFirst = False Then Exit Sub 'user cancelled
Loop Until (vFirst = 1) And (vFirst <= Rows.Count)
Do
vLast = Application.InputBox( _
Prompt:="Please input the last row number", _
Title:="Copy Rows", _
Default:=vFirst, _
Type:=1)
If vLast = False Then Exit Sub 'user cancelled
Loop Until (vLast = vFirst) And (vLast <= Rows.Count)
ActiveSheet.Rows(vFirst & ":" & vLast).Copy _
Destination:=Sheets("Sheet2").Range("A1")


In article ,
Wu wrote:

I want to write a marco that to copy few specified rows from sheet 1 to sheet
2:
.................................................. ............................
.........................
R=Inputbox("pls input the first row number")
R1=inputbox("pls input the last row number")

Rows(R:R1).Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste

.................................................. ............................
...........................

But, the above macro is not work at "Rows(R:R1).Select", I would like to use
inputbox to enter specified number of row to copy from sheet1 to sheet2. How
to do that???


Don Guillett

difficult question
 
try this from anywhere in the workbook
Sub copyslectedrows()
R = InputBox("pls input the first row number")
R1 = InputBox("pls input the last row number")
With Sheets("sheet2")
lr = .Cells(Rows.Count, "a").End(xlUp).Row+1
sheets("source").Rows(R & ":" & R1).Copy .Rows(lr)
End With
End Sub


--
Don Guillett
SalesAid Software

"Wu" wrote in message
...
I want to write a marco that to copy few specified rows from sheet 1 to
sheet
2:
.................................................. .................................................. ...
R=Inputbox("pls input the first row number")
R1=inputbox("pls input the last row number")

Rows(R:R1).Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste

.................................................. .................................................. .....

But, the above macro is not work at "Rows(R:R1).Select", I would like to
use
inputbox to enter specified number of row to copy from sheet1 to sheet2.
How
to do that???





All times are GMT +1. The time now is 03:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com