Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default help with altering 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 any rows populted, but just the data in 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 with number 3 since that is the row that
the data starts on.

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.programming
external usenet poster
 
Posts: 3,986
Default help with altering existing code

This might be your problem area.

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

What you are setting your critria on is xr,Col "A" and xr,Col "B" and
telling it to copy xr, Col "A" : xr, Col "B"

I believe you stated that it was columns B and C that you wanted to copy.
Try this:

For xr = 1 To xlr
If Len(Trim(.Cells(xr, 2))) 0 Or Len(Trim(.Cells(xr, 3))) 0 Then
..Range(.Cells(xr, 2), .Cells(xr, 3)).Copy


"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 any rows populted, but just the data in 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 with number 3 since that is the row that
the data starts on.

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default help with altering existing code

Thanks for the suggestion, I made the change but the data in the rows is not
being copied to the summary, only the words

"ColumnB" in Row 3, Col B
"ColumnC" in Row 3, Col C
"Source WS" in Row 3 Col D and
"Source Row" in Row 3 Col E

The data in the rows in the worksheets is not being copied, do you have any
other suggestions. Thanks

"JLGWhiz" wrote:

This might be your problem area.

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

What you are setting your critria on is xr,Col "A" and xr,Col "B" and
telling it to copy xr, Col "A" : xr, Col "B"

I believe you stated that it was columns B and C that you wanted to copy.
Try this:

For xr = 1 To xlr
If Len(Trim(.Cells(xr, 2))) 0 Or Len(Trim(.Cells(xr, 3))) 0 Then
.Range(.Cells(xr, 2), .Cells(xr, 3)).Copy


"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 any rows populted, but just the data in 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 with number 3 since that is the row that
the data starts on.

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
Really need help with existing code. Cam Excel Discussion (Misc queries) 0 August 12th 08 07:14 PM
Help with existing code ploddinggaltn Excel Discussion (Misc queries) 1 November 27th 06 09:46 PM
altering URLs with code imimin[_3_] Excel Programming 1 August 23rd 06 04:31 AM
Altering code to accomodate empty space JOUIOUI Excel Programming 2 June 28th 06 05:17 PM
Altering code to reference the worksheet before the active worksheet KimberlyC Excel Programming 8 March 15th 05 10:26 PM


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