#1   Report Post  
Kel
 
Posts: n/a
Default Help with copy macro

I have many tabs that I want to copy information into a new sheet
within the same workbook. I need to Copy A5 into Column A, A10 into
Column B, C3 into Column C. Column D needs to be a total, which is
listed in Column H, but it in different cells, the cell above it always
says Balance. Column E needs to be the last populated cell in the
column that says balance.

I have the following macro, how do I adjust it to get the additional
data?

Sub Copy_Data()
Dim w As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
For Each w In ActiveWorkbook.Worksheets
w.Range("A1").Copy Destination:=Sheets("CopyTo") _
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Thanks!

  #2   Report Post  
Otto Moehrbach
 
Posts: n/a
Default

This macro gets some of what you want, but I couldn't figure out what you
wanted with:
"Column D needs to be a total, which is listed in Column H, but it in
different cells, the cell above it always
says Balance. Column E needs to be the last populated cell in the column
that says balance."
Sub Copy_Data()
Dim w As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
For Each w In ActiveWorkbook.Worksheets
Set Dest = [A1]
With Sheets(w)
.[A5].Copy Dest
.[A10].Copy Dest.Offset(, 1)
.[C3].Copy Dest.Offset(, 2)
End With
Set Dest = Dest.Offset(1)
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Post back with more detail about that above part. HTH Otto

"Kel" wrote in message
oups.com...
I have many tabs that I want to copy information into a new sheet
within the same workbook. I need to Copy A5 into Column A, A10 into
Column B, C3 into Column C. Column D needs to be a total, which is
listed in Column H, but it in different cells, the cell above it always
says Balance. Column E needs to be the last populated cell in the
column that says balance.

I have the following macro, how do I adjust it to get the additional
data?

Sub Copy_Data()
Dim w As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
For Each w In ActiveWorkbook.Worksheets
w.Range("A1").Copy Destination:=Sheets("CopyTo") _
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Thanks!



  #3   Report Post  
Kel
 
Posts: n/a
Default

In my new sheet, I'd like column D to be a cell that's listed in column
H of the old sheets. The cell is never in the same exact location.
The cell above the cell I want always has the word Balance in the cell
above it. The word Balance is only listed in column H on the old
sheets. Is there a way to have the macro do a find for Balance and
then copy the cell that is one below? As for column E for the new
sheet, it needs to be the last populated cell in column H. Maybe
easiest to do a find for Balance then do an end down??

Thanks a million for the help!!
Kelly

  #4   Report Post  
Otto Moehrbach
 
Posts: n/a
Default

Kel
Here it is. Lat me know if this works for you. HTH Otto
Sub Copy_Data()
Dim w As Worksheet
Dim CopytoSheet As Worksheet
Dim Dest As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
Set Dest = [A1]
For Each w In ActiveWorkbook.Worksheets
If w.Name = "Copyto" Then GoTo NextSht
With w
.[A5].Copy Dest
.[A10].Copy Dest.Offset(, 1)
.[C3].Copy Dest.Offset(, 2)
.Columns("H:H").Find(What:="Balance",
LookAt:=xlWhole).Offset(1).Copy Dest.Offset(, 3)
.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)
End With
Set Dest = Dest.Offset(1)
NextSht:
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
"Kel" wrote in message
oups.com...
In my new sheet, I'd like column D to be a cell that's listed in column
H of the old sheets. The cell is never in the same exact location.
The cell above the cell I want always has the word Balance in the cell
above it. The word Balance is only listed in column H on the old
sheets. Is there a way to have the macro do a find for Balance and
then copy the cell that is one below? As for column E for the new
sheet, it needs to be the last populated cell in column H. Maybe
easiest to do a find for Balance then do an end down??

Thanks a million for the help!!
Kelly



  #5   Report Post  
Kel
 
Posts: n/a
Default

Hi, getting a syntax error on this part...how do I fix it?
.Columns("H:H").Find(What:="Balance",
LookAt:=xlWhole).Offset(1).Copy Dest.Offset(, 3)
.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)



  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

You got hit by a linewrap in the newsgroup post:

Option Explicit

Sub Copy_Data()
Dim w As Worksheet
Dim CopytoSheet As Worksheet
Dim Dest As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
Set Dest = [A1]
For Each w In ActiveWorkbook.Worksheets
If w.Name = "Copyto" Then GoTo NextSht
With w
.[A5].Copy Dest
.[A10].Copy Dest.Offset(, 1)
.[C3].Copy Dest.Offset(, 2)
.Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole).Offset(1).Copy Dest.Offset(, 3)
.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)
End With
Set Dest = Dest.Offset(1)
NextSht:
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub




Kel wrote:

Hi, getting a syntax error on this part...how do I fix it?
.Columns("H:H").Find(What:="Balance",
LookAt:=xlWhole).Offset(1).Copy Dest.Offset(, 3)
.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)


--

Dave Peterson
  #7   Report Post  
Kel
 
Posts: n/a
Default

Thanks. I fixed it, now I have an object variable or with variable not
set. This is the text that is coming back highlighted.

..Columns("H:H").Find(What:="Balance", LookAt:=xlWhole).Offset(1).Copy
Dest.Offset(, 3)

  #8   Report Post  
Dave Peterson
 
Posts: n/a
Default

Now it becomes what should happen if that "balance" isn't found.

This compiled, but I'm not sure it's what you want to do:

Option Explicit
Sub Copy_Data()
Dim w As Worksheet
Dim CopytoSheet As Worksheet
Dim FoundCell As Range
Dim Dest As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
Set Dest = [A1]
For Each w In ActiveWorkbook.Worksheets
If w.Name = "Copyto" Then GoTo NextSht
With w
.[A5].Copy Dest
.[A10].Copy Dest.Offset(, 1)
.[C3].Copy Dest.Offset(, 2)
Set FoundCell = .Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole)

If FoundCell Is Nothing Then
MsgBox "Not found!"
'what should be done
Else
FoundCell.Offset(1).Copy Dest.Offset(, 3)
End If


.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)
End With
Set Dest = Dest.Offset(1)
NextSht:
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub



Kel wrote:

Thanks. I fixed it, now I have an object variable or with variable not
set. This is the text that is coming back highlighted.

.Columns("H:H").Find(What:="Balance", LookAt:=xlWhole).Offset(1).Copy
Dest.Offset(, 3)


--

Dave Peterson
  #9   Report Post  
Kel
 
Posts: n/a
Default

Thanks. It works well, one small issue though...the message box is
coming up even though it is populating the new sheet correctly. Why is
the box coming up if it is finding the value?

  #10   Report Post  
Dave Peterson
 
Posts: n/a
Default

That message box should only come up with Balance wasn't found:

But this line will execute whether or not it was found:

..Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)



Kel wrote:

Thanks. It works well, one small issue though...the message box is
coming up even though it is populating the new sheet correctly. Why is
the box coming up if it is finding the value?


--

Dave Peterson


  #11   Report Post  
Kel
 
Posts: n/a
Default

The message box is coming up either way, if balance is found or not.
Then, the new sheet is being populated correctly, with the cell below
the balance. All 5 columns are being populated.

Is there a way to just leave the cell blank and continue if balance
isn't found??

Thanks a million!!


Dave Peterson wrote:
That message box should only come up with Balance wasn't found:

But this line will execute whether or not it was found:

.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)



Kel wrote:

Thanks. It works well, one small issue though...the message box is
coming up even though it is populating the new sheet correctly.

Why is
the box coming up if it is finding the value?


--

Dave Peterson


  #12   Report Post  
Dave Peterson
 
Posts: n/a
Default

If that message is coming up either way, then this code was modified:

Set FoundCell = .Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole)

If FoundCell Is Nothing Then
MsgBox "Not found!"
'what should be done
Else
FoundCell.Offset(1).Copy Dest.Offset(, 3)
End If

If you changed the code, you may want to post what you're using.



Kel wrote:

The message box is coming up either way, if balance is found or not.
Then, the new sheet is being populated correctly, with the cell below
the balance. All 5 columns are being populated.

Is there a way to just leave the cell blank and continue if balance
isn't found??

Thanks a million!!

Dave Peterson wrote:
That message box should only come up with Balance wasn't found:

But this line will execute whether or not it was found:

.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)



Kel wrote:

Thanks. It works well, one small issue though...the message box is
coming up even though it is populating the new sheet correctly.

Why is
the box coming up if it is finding the value?


--

Dave Peterson


--

Dave Peterson
  #13   Report Post  
Kel
 
Posts: n/a
Default

Thanks...Now, I have one more issue that I can't figure out. All the
cells in Column H are formulas. I didn't realize that it would make a
difference. How do I change this so that I get the value for the 2
cells that I need in column H? Here's the code that I'm using:

Sub Copy_Data()
Dim w As Worksheet
Dim CopytoSheet As Worksheet
Dim FoundCell As Range


Dim Dest As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
Set Dest = [A1]
For Each w In ActiveWorkbook.Worksheets
If w.Name = "Copyto" Then GoTo NextSht
With w
.[A5].Copy Dest
.[A10].Copy Dest.Offset(, 1)
.[C3].Copy Dest.Offset(, 2)
Set FoundCell = .Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole)

If FoundCell Is Nothing Then
MsgBox "Not found!"
'what should be done
Else
FoundCell.Offset(1).Copy Dest.Offset(, 3)
End If


.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)
End With
Set Dest = Dest.Offset(1)
NextSht:
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Also, the message box is still coming up, but pressing enter gets me
right through it. Not sure what that's about, but I'm willing to hit
enter if necessary.

Thanks again,
Kel

Dave Peterson wrote:
If that message is coming up either way, then this code was modified:

Set FoundCell = .Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole)

If FoundCell Is Nothing Then
MsgBox "Not found!"
'what should be done
Else
FoundCell.Offset(1).Copy Dest.Offset(, 3)
End If

If you changed the code, you may want to post what you're using.



Kel wrote:

The message box is coming up either way, if balance is found or

not.
Then, the new sheet is being populated correctly, with the cell

below
the balance. All 5 columns are being populated.

Is there a way to just leave the cell blank and continue if balance
isn't found??

Thanks a million!!

Dave Peterson wrote:
That message box should only come up with Balance wasn't found:

But this line will execute whether or not it was found:

.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)



Kel wrote:

Thanks. It works well, one small issue though...the message

box is
coming up even though it is populating the new sheet correctly.

Why is
the box coming up if it is finding the value?

--

Dave Peterson


--

Dave Peterson


  #14   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'm not sure what line you're writing about:

If it's this one:
FoundCell.Offset(1).Copy Dest.Offset(, 3)
use:
dest.offset(,3).value = foundcell.offset(1).value

or if it's this line:

..Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)

I'd replace it slightly.

Add a declaration line (near the top)
dim RngToCopy as range

Then that single line
..Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)
becomes this block:

set rngtocopy = .Range("H" & Rows.Count).End(xlUp)
Dest.resize(rngtocopy.rows.count,rngtocopy.columns .count).Offset(, 4).value _
= rngtocopy.value





Kel wrote:

Thanks...Now, I have one more issue that I can't figure out. All the
cells in Column H are formulas. I didn't realize that it would make a
difference. How do I change this so that I get the value for the 2
cells that I need in column H? Here's the code that I'm using:

Sub Copy_Data()
Dim w As Worksheet
Dim CopytoSheet As Worksheet
Dim FoundCell As Range

Dim Dest As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set CopytoSheet = Worksheets.Add
CopytoSheet.Name = "Copyto"
Set Dest = [A1]
For Each w In ActiveWorkbook.Worksheets
If w.Name = "Copyto" Then GoTo NextSht
With w
.[A5].Copy Dest
.[A10].Copy Dest.Offset(, 1)
.[C3].Copy Dest.Offset(, 2)
Set FoundCell = .Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole)

If FoundCell Is Nothing Then
MsgBox "Not found!"
'what should be done
Else
FoundCell.Offset(1).Copy Dest.Offset(, 3)
End If

.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)
End With
Set Dest = Dest.Offset(1)
NextSht:
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Also, the message box is still coming up, but pressing enter gets me
right through it. Not sure what that's about, but I'm willing to hit
enter if necessary.

Thanks again,
Kel

Dave Peterson wrote:
If that message is coming up either way, then this code was modified:

Set FoundCell = .Columns("H:H").Find(What:="Balance", _
LookAt:=xlWhole)

If FoundCell Is Nothing Then
MsgBox "Not found!"
'what should be done
Else
FoundCell.Offset(1).Copy Dest.Offset(, 3)
End If

If you changed the code, you may want to post what you're using.



Kel wrote:

The message box is coming up either way, if balance is found or

not.
Then, the new sheet is being populated correctly, with the cell

below
the balance. All 5 columns are being populated.

Is there a way to just leave the cell blank and continue if balance
isn't found??

Thanks a million!!

Dave Peterson wrote:
That message box should only come up with Balance wasn't found:

But this line will execute whether or not it was found:

.Range("H" & Rows.Count).End(xlUp).Copy Dest.Offset(, 4)



Kel wrote:

Thanks. It works well, one small issue though...the message

box is
coming up even though it is populating the new sheet correctly.
Why is
the box coming up if it is finding the value?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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 to delete a text box and copy in new one Dave Excel Discussion (Misc queries) 1 February 18th 05 02:02 AM
Activate a macro to insert a row and copy the formuals from the rows above to the blank row oil_driller Excel Discussion (Misc queries) 1 February 11th 05 03:30 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Need Macro to copy specific sheet mac Excel Worksheet Functions 1 January 17th 05 08:46 PM
copy macro assigned buttons in an array Phatboy_D Excel Worksheet Functions 1 December 1st 04 10:01 PM


All times are GMT +1. The time now is 12:22 PM.

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"