Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Copying A Range of Cells to Another Worksheet

I am trying to copy a range of cells from one worksheet to another
(worksheet); based on the text in a specific cell.

Using the range B2 through H500:
If the text in cell B(x) = "Emergency"
then copy cells H(x), I(x), J(x), C(x), D(x), E(x), F(x), G(x)
into another worksheet in the same order.

(In the above example x represents the range 2 through 500)

I have tried using a formula but that doen not work. Any suggestions in the
form of a formula of a Macro/VBA would be greately appreciated!

Can Anyone Help?

Thanks in Advance.

--
Rodman Veney
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Copying A Range of Cells to Another Worksheet

Hi,

It's a bit messy because of the order you want the data transferring but
this seems to work. Right click the sheet tab of the sheet with your data in,
view code and paste this in and data are copied to sheet 2.

Sub copyit()
Dim MyRange As Range
Set MyRange = Range("B2:B500")
lastrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
For Each c In MyRange
If InStr(1, UCase(c.Value), "EMERGENCY", 0) Then
Sheets("Sheet2").Cells(lastrow, 1).Value = c.Offset(, 6).Value
Sheets("Sheet2").Cells(lastrow, 2).Value = c.Offset(, 7).Value
Sheets("Sheet2").Cells(lastrow, 3).Value = c.Offset(, 8).Value
Sheets("Sheet2").Cells(lastrow, 4).Value = c.Offset(, 1).Value
Sheets("Sheet2").Cells(lastrow, 5).Value = c.Offset(, 2).Value
Sheets("Sheet2").Cells(lastrow, 6).Value = c.Offset(, 3).Value
Sheets("Sheet2").Cells(lastrow, 7).Value = c.Offset(, 4).Value
Sheets("Sheet2").Cells(lastrow, 8).Value = c.Offset(, 5).Value
lastrow = lastrow + 1
End If
Next
End Sub

Mike

"Rodman" wrote:

I am trying to copy a range of cells from one worksheet to another
(worksheet); based on the text in a specific cell.

Using the range B2 through H500:
If the text in cell B(x) = "Emergency"
then copy cells H(x), I(x), J(x), C(x), D(x), E(x), F(x), G(x)
into another worksheet in the same order.

(In the above example x represents the range 2 through 500)

I have tried using a formula but that doen not work. Any suggestions in the
form of a formula of a Macro/VBA would be greately appreciated!

Can Anyone Help?

Thanks in Advance.

--
Rodman Veney

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Copying A Range of Cells to Another Worksheet

Mike,

Thanks for your quick response. It worked fine, however, I failed to
mention that the data being copied into the other worksheet must start at the
third line (this macro moves the data to cells starting at line 1).

Can you give me the modifications?

Thanks!
--
Rodman Veney


"Rodman" wrote:

I am trying to copy a range of cells from one worksheet to another
(worksheet); based on the text in a specific cell.

Using the range B2 through H500:
If the text in cell B(x) = "Emergency"
then copy cells H(x), I(x), J(x), C(x), D(x), E(x), F(x), G(x)
into another worksheet in the same order.

(In the above example x represents the range 2 through 500)

I have tried using a formula but that doen not work. Any suggestions in the
form of a formula of a Macro/VBA would be greately appreciated!

Can Anyone Help?

Thanks in Advance.

--
Rodman Veney

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Copying A Range of Cells to Another Worksheet

Hi,

Only a small change required to do that

Sub copyit()
Dim MyRange As Range
Set MyRange = Range("B2:B500")
If Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row < 3 Then
lastrow = 3
Else
lastrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End If
For Each c In MyRange
If InStr(1, UCase(c.Value), "EMERGENCY", 0) Then
Sheets("Sheet2").Cells(lastrow, 1).Value = c.Offset(, 6).Value
Sheets("Sheet2").Cells(lastrow, 2).Value = c.Offset(, 7).Value
Sheets("Sheet2").Cells(lastrow, 3).Value = c.Offset(, 8).Value
Sheets("Sheet2").Cells(lastrow, 4).Value = c.Offset(, 1).Value
Sheets("Sheet2").Cells(lastrow, 5).Value = c.Offset(, 2).Value
Sheets("Sheet2").Cells(lastrow, 6).Value = c.Offset(, 3).Value
Sheets("Sheet2").Cells(lastrow, 7).Value = c.Offset(, 4).Value
Sheets("Sheet2").Cells(lastrow, 8).Value = c.Offset(, 5).Value
lastrow = lastrow + 1
End If
Next
End Sub

Mike

"Rodman" wrote:

Mike,

Thanks for your quick response. It worked fine, however, I failed to
mention that the data being copied into the other worksheet must start at the
third line (this macro moves the data to cells starting at line 1).

Can you give me the modifications?

Thanks!
--
Rodman Veney


"Rodman" wrote:

I am trying to copy a range of cells from one worksheet to another
(worksheet); based on the text in a specific cell.

Using the range B2 through H500:
If the text in cell B(x) = "Emergency"
then copy cells H(x), I(x), J(x), C(x), D(x), E(x), F(x), G(x)
into another worksheet in the same order.

(In the above example x represents the range 2 through 500)

I have tried using a formula but that doen not work. Any suggestions in the
form of a formula of a Macro/VBA would be greately appreciated!

Can Anyone Help?

Thanks in Advance.

--
Rodman Veney

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default Copying A Range of Cells to Another Worksheet

Thanks For Your Help!
--
Rodman Veney


"Mike H" wrote:

Hi,

Only a small change required to do that

Sub copyit()
Dim MyRange As Range
Set MyRange = Range("B2:B500")
If Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row < 3 Then
lastrow = 3
Else
lastrow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
End If
For Each c In MyRange
If InStr(1, UCase(c.Value), "EMERGENCY", 0) Then
Sheets("Sheet2").Cells(lastrow, 1).Value = c.Offset(, 6).Value
Sheets("Sheet2").Cells(lastrow, 2).Value = c.Offset(, 7).Value
Sheets("Sheet2").Cells(lastrow, 3).Value = c.Offset(, 8).Value
Sheets("Sheet2").Cells(lastrow, 4).Value = c.Offset(, 1).Value
Sheets("Sheet2").Cells(lastrow, 5).Value = c.Offset(, 2).Value
Sheets("Sheet2").Cells(lastrow, 6).Value = c.Offset(, 3).Value
Sheets("Sheet2").Cells(lastrow, 7).Value = c.Offset(, 4).Value
Sheets("Sheet2").Cells(lastrow, 8).Value = c.Offset(, 5).Value
lastrow = lastrow + 1
End If
Next
End Sub

Mike

"Rodman" wrote:

Mike,

Thanks for your quick response. It worked fine, however, I failed to
mention that the data being copied into the other worksheet must start at the
third line (this macro moves the data to cells starting at line 1).

Can you give me the modifications?

Thanks!
--
Rodman Veney


"Rodman" wrote:

I am trying to copy a range of cells from one worksheet to another
(worksheet); based on the text in a specific cell.

Using the range B2 through H500:
If the text in cell B(x) = "Emergency"
then copy cells H(x), I(x), J(x), C(x), D(x), E(x), F(x), G(x)
into another worksheet in the same order.

(In the above example x represents the range 2 through 500)

I have tried using a formula but that doen not work. Any suggestions in the
form of a formula of a Macro/VBA would be greately appreciated!

Can Anyone Help?

Thanks in Advance.

--
Rodman Veney

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
universal copying over worksheet range pat in chard Excel Discussion (Misc queries) 1 April 23rd 08 12:51 PM
Copying cell with input range to different worksheet Doug T[_2_] Excel Worksheet Functions 4 October 4th 07 04:11 PM
Copying a worksheet witrh protected cells to a new worksheet John Excel Worksheet Functions 2 February 1st 06 02:19 PM
Problem copying formula to range of cells Bob DePass Setting up and Configuration of Excel 0 July 22nd 05 02:09 AM
How do I skip blank cells when copying over a range of cells? tawells Excel Discussion (Misc queries) 2 June 7th 05 09:36 PM


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