Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Help with existing code

I found this code in another post and tried to alter it to accomodate my
application but it is not working for me. Any help you can give me is
appreciated, thank you.

I have a WB with 11 WS followed by a worksheet titled, "Summary". I have a
button on the Summary and when it in clicked I need this code to bring in the
data from Col B and Col C from each of the previous 11 WS and copy that data
to col B and C on the Summary WS beginning with row 3. Then for each cell on
the summary page that is populated with data in Col B, I need it to add the
number of the row in Col A beginning iwth number 3 since that is the row that
the data starts at.

Currently I have this code stored in the Summary Page. Thanks again for
your help.

Sub PopulateSummary()
Dim wSh As Worksheet, wTarget As Worksheet
Dim xlr As Long, xr As Long, xTarget As Long

' set up final sheet
Set wTarget = Worksheets("Summary")
With wTarget
.Cells.ClearContents
.Cells(3, 1) = "ColumnB"
.Cells(3, 2) = "ColumnC"
.Cells(3, 3) = "Source WS"
.Cells(3, 4) = "Source Row"
End With
xTarget = 2

' scan all Sheets prefixed WS and copy to target
For Each wSh In ActiveWorkbook.Worksheets
If UCase(Left(wSh.Name, 2)) = "WS" Then
With wSh
xlr = .Cells(.Rows.Count, "B").End(xlUp).Row
If .Cells(.Rows.Count, "C").End(xlUp).Row xlr Then _
xlr = .Cells(.Rows.Count, "C").End(xlUp).Row
For xr = 1 To xlr
If Len(Trim(.Cells(xr, 1))) 0 Or Len(Trim(.Cells(xr, 2))) 0 Then
.Range(.Cells(xr, 1), .Cells(xr, 2)).Copy
Destination:=wTarget.Cells(xTarget, 1)
wTarget.Cells(xTarget, 3) = wSh.Name
wTarget.Cells(xTarget, 4) = xr
xTarget = xTarget + 1
End If
Next xr
End With
End If
Next wSh

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Help with existing code

Sorry, I posted this question on the incorrect topic site

"ploddinggaltn" wrote:

I found this code in another post and tried to alter it to accomodate my
application but it is not working for me. Any help you can give me is
appreciated, thank you.

I have a WB with 11 WS followed by a worksheet titled, "Summary". I have a
button on the Summary and when it in clicked I need this code to bring in the
data from Col B and Col C from each of the previous 11 WS and copy that data
to col B and C on the Summary WS beginning with row 3. Then for each cell on
the summary page that is populated with data in Col B, I need it to add the
number of the row in Col A beginning iwth number 3 since that is the row that
the data starts at.

Currently I have this code stored in the Summary Page. Thanks again for
your help.

Sub PopulateSummary()
Dim wSh As Worksheet, wTarget As Worksheet
Dim xlr As Long, xr As Long, xTarget As Long

' set up final sheet
Set wTarget = Worksheets("Summary")
With wTarget
.Cells.ClearContents
.Cells(3, 1) = "ColumnB"
.Cells(3, 2) = "ColumnC"
.Cells(3, 3) = "Source WS"
.Cells(3, 4) = "Source Row"
End With
xTarget = 2

' scan all Sheets prefixed WS and copy to target
For Each wSh In ActiveWorkbook.Worksheets
If UCase(Left(wSh.Name, 2)) = "WS" Then
With wSh
xlr = .Cells(.Rows.Count, "B").End(xlUp).Row
If .Cells(.Rows.Count, "C").End(xlUp).Row xlr Then _
xlr = .Cells(.Rows.Count, "C").End(xlUp).Row
For xr = 1 To xlr
If Len(Trim(.Cells(xr, 1))) 0 Or Len(Trim(.Cells(xr, 2))) 0 Then
.Range(.Cells(xr, 1), .Cells(xr, 2)).Copy
Destination:=wTarget.Cells(xTarget, 1)
wTarget.Cells(xTarget, 3) = wSh.Name
wTarget.Cells(xTarget, 4) = xr
xTarget = xTarget + 1
End If
Next xr
End With
End If
Next wSh

End Sub


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
Text formatting Kace Excel Worksheet Functions 1 September 18th 06 08:28 PM
code not unique find latest date Barbara Wiseman Excel Discussion (Misc queries) 3 December 11th 05 08:50 AM
Complicated If Then / V Lookup / Match Statement... ryesworld Excel Worksheet Functions 17 December 10th 05 02:09 PM
Conform a total to a list of results? xmaveric Excel Discussion (Misc queries) 1 August 21st 05 07:22 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM


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