Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in Column A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or BB33
in Column A). Once the range has been selected from Sheet1 the code copies it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I dont have to specify the data that
needs to be in Column A. As a result the code will start in row 5 of Sheet1
and scan every row in Column A for any data. When the last row of data in
Column A is found I would like for the macro to select down to that row and
over to Column C, so I am selecting the range A5:C? (unknown row based on
last row of data in Column A). Once the range has been selected from Sheet1
I would like for the code to copy the range and insert the copied cells into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just dont
want to specify what data I want it to look for. I want it to look for any
data in Column A and then perform the same steps it already does. Can you
help me?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Select, copy, insert, then paste.

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can you
help me?



  #3   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can you
help me?



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select, copy, insert, then paste.

try:

Set rng = sh.Range("A5:C" & lr)



Sal wrote:

Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?

"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can you
help me?



.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Select, copy, insert, then paste.

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is
found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data
that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data
in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based
on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just
don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can
you
help me?



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

This is cool. Thank you for the help. It works well. I probably didnt
communicate the last part clearly. I want to be able to use the macro to
collect data, so I will be using it more than once. Each time I run the
macro Id like to be able to insert the copied cells into Sheet2 so what was
already copied and pasted into Sheet2 moves down a couple rows in the
worksheet to make space for the new data. In other words each time I run the
macro the existing rows in Sheet2 are shifted down and the new data takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is
found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data
that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data
in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based
on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just
don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can
you
help me?



.



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

Thanks for the tip. I appreciate your help.

"Dave Peterson" wrote:

try:

Set rng = sh.Range("A5:C" & lr)



Sal wrote:

Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?

"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can you
help me?



.


--

Dave Peterson
.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Select, copy, insert, then paste.

This should do it:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"Sal" wrote:

This is cool. Thank you for the help. It works well. I probably didnt
communicate the last part clearly. I want to be able to use the macro to
collect data, so I will be using it more than once. Each time I run the
macro Id like to be able to insert the copied cells into Sheet2 so what was
already copied and pasted into Sheet2 moves down a couple rows in the
worksheet to make space for the new data. In other words each time I run the
macro the existing rows in Sheet2 are shifted down and the new data takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is
found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data
that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data
in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based
on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just
don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can
you
help me?



.



.

  #9   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

O darn for some reason its inserting the copied cells into the same worksheet
they were copied from instead of inserting them into Sheet2. I am not sure
how to fix it. Any thoughts.

"JLGWhiz" wrote:

This should do it:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"Sal" wrote:

This is cool. Thank you for the help. It works well. I probably didnt
communicate the last part clearly. I want to be able to use the macro to
collect data, so I will be using it more than once. Each time I run the
macro Id like to be able to insert the copied cells into Sheet2 so what was
already copied and pasted into Sheet2 moves down a couple rows in the
worksheet to make space for the new data. In other words each time I run the
macro the existing rows in Sheet2 are shifted down and the new data takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA is asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A" &
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or BB33 is
found
the macro will select down to that row and over to Column C, so I am
selecting the range A5:C?(unknown row based on last row of text AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the data
that
needs to be in Column A. As a result the code will start in row 5 of
Sheet1
and scan every row in Column A for any data. When the last row of data
in
Column A is found I would like for the macro to select down to that row
and
over to Column C, so I am selecting the range A5:C? (unknown row based
on
last row of data in Column A). Once the range has been selected from
Sheet1
I would like for the code to copy the range and insert the copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I just
don't
want to specify what data I want it to look for. I want it to look for
any
data in Column A and then perform the same steps it already does. Can
you
help me?



.



.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Select, copy, insert, then paste.

Change Sheets(2) in this line:

Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown

To the actual sheet name that you want to copy to. i.e. Sheets("Sheet3") or
whatever it is.

Apparently the sheet you are copying from is the second tab from the left,
which would make it Sheets(2), so use the sheet name instead of the index
number.




"Sal" wrote in message
...
O darn for some reason its inserting the copied cells into the same
worksheet
they were copied from instead of inserting them into Sheet2. I am not
sure
how to fix it. Any thoughts.

"JLGWhiz" wrote:

This should do it:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"Sal" wrote:

This is cool. Thank you for the help. It works well. I probably didn't
communicate the last part clearly. I want to be able to use the macro
to
collect data, so I will be using it more than once. Each time I run
the
macro I'd like to be able to insert the copied cells into Sheet2 so
what was
already copied and pasted into Sheet2 moves down a couple rows in the
worksheet to make space for the new data. In other words each time I
run the
macro the existing rows in Sheet2 are shifted down and the new data
takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA is
asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row
in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or
BB33 is
found
the macro will select down to that row and over to Column C, so
I am
selecting the range A5:C?(unknown row based on last row of text
AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the
code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the
data
that
needs to be in Column A. As a result the code will start in row
5 of
Sheet1
and scan every row in Column A for any data. When the last row
of data
in
Column A is found I would like for the macro to select down to
that row
and
over to Column C, so I am selecting the range A5:C? (unknown row
based
on
last row of data in Column A). Once the range has been selected
from
Sheet1
I would like for the code to copy the range and insert the
copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I
just
don't
want to specify what data I want it to look for. I want it to
look for
any
data in Column A and then perform the same steps it already
does. Can
you
help me?



.



.





  #11   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

Hi again. I wanted to thank you again for your help; I appreciate it a lot.
Maybe I made a mistake. I posted the code below that I am using but its
still giving me a Run-time error '9'; subscript out of range error message.
Any thoughts?


Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(Sheet2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"JLGWhiz" wrote:

Change Sheets(2) in this line:

Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown

To the actual sheet name that you want to copy to. i.e. Sheets("Sheet3") or
whatever it is.

Apparently the sheet you are copying from is the second tab from the left,
which would make it Sheets(2), so use the sheet name instead of the index
number.




"Sal" wrote in message
...
O darn for some reason its inserting the copied cells into the same
worksheet
they were copied from instead of inserting them into Sheet2. I am not
sure
how to fix it. Any thoughts.

"JLGWhiz" wrote:

This should do it:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"Sal" wrote:

This is cool. Thank you for the help. It works well. I probably didn't
communicate the last part clearly. I want to be able to use the macro
to
collect data, so I will be using it more than once. Each time I run
the
macro I'd like to be able to insert the copied cells into Sheet2 so
what was
already copied and pasted into Sheet2 moves down a couple rows in the
worksheet to make space for the new data. In other words each time I
run the
macro the existing rows in Sheet2 are shifted down and the new data
takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA is
asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1, After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2, After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every row
in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or
BB33 is
found
the macro will select down to that row and over to Column C, so
I am
selecting the range A5:C?(unknown row based on last row of text
AA22 or
BB33
in Column A). Once the range has been selected from Sheet1 the
code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify the
data
that
needs to be in Column A. As a result the code will start in row
5 of
Sheet1
and scan every row in Column A for any data. When the last row
of data
in
Column A is found I would like for the macro to select down to
that row
and
over to Column C, so I am selecting the range A5:C? (unknown row
based
on
last row of data in Column A). Once the range has been selected
from
Sheet1
I would like for the code to copy the range and insert the
copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function I
just
don't
want to specify what data I want it to look for. I want it to
look for
any
data in Column A and then perform the same steps it already
does. Can
you
help me?



.



.



.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Select, copy, insert, then paste.

You just needed some quote marks. Try this:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets("Sheet2").Range("A2").Resize(rng.Rows.Count , 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub




"Sal" wrote in message
...
Hi again. I wanted to thank you again for your help; I appreciate it a
lot.
Maybe I made a mistake. I posted the code below that I am using but its
still giving me a Run-time error '9'; subscript out of range error
message.
Any thoughts?


Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(Sheet2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"JLGWhiz" wrote:

Change Sheets(2) in this line:

Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown

To the actual sheet name that you want to copy to. i.e. Sheets("Sheet3")
or
whatever it is.

Apparently the sheet you are copying from is the second tab from the
left,
which would make it Sheets(2), so use the sheet name instead of the index
number.




"Sal" wrote in message
...
O darn for some reason its inserting the copied cells into the same
worksheet
they were copied from instead of inserting them into Sheet2. I am not
sure
how to fix it. Any thoughts.

"JLGWhiz" wrote:

This should do it:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert
Shift:=xlDown
Application.CutCopyMode = False
End Sub



"Sal" wrote:

This is cool. Thank you for the help. It works well. I probably
didn't
communicate the last part clearly. I want to be able to use the
macro
to
collect data, so I will be using it more than once. Each time I run
the
macro I'd like to be able to insert the copied cells into Sheet2 so
what was
already copied and pasted into Sheet2 moves down a couple rows in
the
worksheet to make space for the new data. In other words each time
I
run the
macro the existing rows in Sheet2 are shifted down and the new data
takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA
is
asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1,
After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2,
After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every
row
in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or
BB33 is
found
the macro will select down to that row and over to Column C,
so
I am
selecting the range A5:C?(unknown row based on last row of
text
AA22 or
BB33
in Column A). Once the range has been selected from Sheet1
the
code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify
the
data
that
needs to be in Column A. As a result the code will start in
row
5 of
Sheet1
and scan every row in Column A for any data. When the last
row
of data
in
Column A is found I would like for the macro to select down
to
that row
and
over to Column C, so I am selecting the range A5:C? (unknown
row
based
on
last row of data in Column A). Once the range has been
selected
from
Sheet1
I would like for the code to copy the range and insert the
copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function
I
just
don't
want to specify what data I want it to look for. I want it
to
look for
any
data in Column A and then perform the same steps it already
does. Can
you
help me?



.



.



.



  #13   Report Post  
Posted to microsoft.public.excel.programming
Sal Sal is offline
external usenet poster
 
Posts: 84
Default Select, copy, insert, then paste.

Wow, I feel foolish. Thanks for the help. You were right!

"JLGWhiz" wrote:

You just needed some quote marks. Try this:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets("Sheet2").Range("A2").Resize(rng.Rows.Count , 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub




"Sal" wrote in message
...
Hi again. I wanted to thank you again for your help; I appreciate it a
lot.
Maybe I made a mistake. I posted the code below that I am using but its
still giving me a Run-time error '9'; subscript out of range error
message.
Any thoughts?


Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(Sheet2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub



"JLGWhiz" wrote:

Change Sheets(2) in this line:

Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert Shift:=xlDown

To the actual sheet name that you want to copy to. i.e. Sheets("Sheet3")
or
whatever it is.

Apparently the sheet you are copying from is the second tab from the
left,
which would make it Sheets(2), so use the sheet name instead of the index
number.




"Sal" wrote in message
...
O darn for some reason its inserting the copied cells into the same
worksheet
they were copied from instead of inserting them into Sheet2. I am not
sure
how to fix it. Any thoughts.

"JLGWhiz" wrote:

This should do it:

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A5:C" & lr)
rng.Copy
Sheets(2).Range("A2").Resize(rng.Rows.Count, 3).Insert
Shift:=xlDown
Application.CutCopyMode = False
End Sub



"Sal" wrote:

This is cool. Thank you for the help. It works well. I probably
didn't
communicate the last part clearly. I want to be able to use the
macro
to
collect data, so I will be using it more than once. Each time I run
the
macro I'd like to be able to insert the copied cells into Sheet2 so
what was
already copied and pasted into Sheet2 moves down a couple rows in
the
worksheet to make space for the new data. In other words each time
I
run the
macro the existing rows in Sheet2 are shifted down and the new data
takes its
place. Does that make sense?

"JLGWhiz" wrote:

My error, should be:

Set rng = sh.Range("A5:C" & lr)



"Sal" wrote in message
...
Hi thanks for the insight. Perhaps I am making a mistake. VBA
is
asking
me
to debug this line of code.

rng = sh.Range("A5:C" & lr)

I am getting an error message that says

Run-time error '91':
Object variable or With block variable not set

Any thoughts?


"JLGWhiz" wrote:

Give this a try.

Sub copyStuff()
Dim lr As Long, rng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
rng = sh.Range("A5:C" & lr)
rng.Copy Sheets("Sheet2").Range("A2")
End Sub




"Sal" wrote in message
...
Sub CopyInsertPaste()
Dim Sws As Worksheet, Dws As Worksheet
Dim Val1 As Variant, Val2 As Variant
Dim Val1Row As Long, Val2Row As Long, MyRow As Long

Val1 = "AA22"
Val2 = "BB33"

Set Sws = Sheets("Sheet1") '<---Sheet copying from
Set Dws = Sheets("Sheet2") '<---Sheet pasting to
On Error Resume Next
Val1Row = Sws.Range("A:A").Find(What:=Val1,
After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row

Val2Row = Sws.Range("A:A").Find(What:=Val2,
After:=Sws.Range("A"
&
Rows.Count), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious,
MatchCase:= _
False, SearchFormat:=False).Row
On Error GoTo 0
MyRow = Application.Max(Val1Row, Val2Row)
Sws.Range("A5:C" & MyRow).Copy
Dws.Range("A2").Insert Shift:=xlDown
End Sub


The code above will start in row 5 of Sheet1 and scan every
row
in
Column
A
for the data AA22 or BB33. When the last row of data AA22 or
BB33 is
found
the macro will select down to that row and over to Column C,
so
I am
selecting the range A5:C?(unknown row based on last row of
text
AA22 or
BB33
in Column A). Once the range has been selected from Sheet1
the
code
copies
it
and inserts the copied cells into Sheet2 starting in Row 2.

I would like to change this macro so I don't have to specify
the
data
that
needs to be in Column A. As a result the code will start in
row
5 of
Sheet1
and scan every row in Column A for any data. When the last
row
of data
in
Column A is found I would like for the macro to select down
to
that row
and
over to Column C, so I am selecting the range A5:C? (unknown
row
based
on
last row of data in Column A). Once the range has been
selected
from
Sheet1
I would like for the code to copy the range and insert the
copied cells
into
Sheet2 starting in Row2.

In other words the code above is performing the same function
I
just
don't
want to specify what data I want it to look for. I want it
to
look for
any
data in Column A and then perform the same steps it already
does. Can
you
help me?



.



.



.



.

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
Copy and paste versus copy and insert copied cells Alana New Users to Excel 1 September 28th 07 08:58 PM
I want to select a row and insert a copy later in the worksheet Dennis Milns Excel Worksheet Functions 3 June 26th 07 12:39 AM
Macro that will select and insert a new row and paste as value [email protected] Excel Worksheet Functions 3 December 5th 06 04:06 AM
Simple (?) Macro Assistance- Select, Insert, Paste, Rinse, Repeat Pete_CSC Excel Programming 4 June 15th 04 05:09 PM
Select All and copy and paste Ashok[_2_] Excel Programming 7 November 11th 03 03:46 AM


All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"