PDA

View Full Version : Copy preferred row to same named Sheet



bobby_793
04-09-2008, 06:55 AM
halloo

I attached one workbook by the name of Test. I have a huge data in this work sheet for atmost 2 years. All that data in sheet (Main) if you see other sheet i have different names like , Basic Fee, Incentive fee, reservation fee, GSI. These worksheet names are based on the worksheet (main) in description. Now i want a code, what every i have in Main sheet in Description colums should copy to respactive sheet .

Note :- Description and the sheet name are same.

Thank you in advance to help me

Bobby

mdmackillop
04-09-2008, 07:25 AM
Please give your questions meaningful titles.

bobby_793
04-09-2008, 07:45 AM
dear mdmackillop

I didn't get you ? anyway my question is like that as below

DateInvoice #Ref DocDescriptionAmount PymtBalanceRemarks31-Mar-088000001231479Basic Fee12000 12000Under Approval31-Mar-088000001525987Incentive Fee25000 25000Under Approval31-Mar-089000001675977Reservation Fee50000 50000Under Approval31-Mar-087000009879878GSI 689 689Under Approval 87689087689

Now my other sheet are baseed on the name mentioned in description. I want a code that "basic fee" row will copy to "basic fee" sheet and like other as well

mdmackillop
04-09-2008, 08:43 AM
Most people who post here "Need Help", so what does this add to the benefit of the forum. I see you've used it before, so searching becomes even more meaningless.
A question was posted the other day If Cell Value is Worksheet Name Copy Row (http://www.vbaexpress.com/forum/showthread.php?t=18882) (is that not a sensible title?) which appears to be what you are after.

bobby_793
04-09-2008, 11:08 PM
sorry mdmackillop, i am still new in VBA and in this form. I think i should relinquish from this form. Thank you all of you to help me with some code and thanks for giving me good lesson. Thank you mdmackillop.

Bye
Bobby

bobby_793
04-13-2008, 03:39 AM
halloo

I attached one workbook by the name of Test. I have a huge data in this work sheet for atmost 2 years. All that data in my master sheet by the name of "Main" if you see other sheets i have different names like , Basic Fee, Incentive fee, reservation fee, GSI. These worksheet names are same as the description rows in sheet "Main". Now i want a code, what every i have in Main sheet copy to respactive sheet .

Thank you in advance to help me

Bobby

tstav
04-13-2008, 03:56 AM
Hi Bobby
where is the attachment?

bobby_793
04-13-2008, 06:19 AM
here is the link

http://www.vbaexpress.com/forum/showpost.php?p=139397&postcount=1

Thank you

tstav
04-13-2008, 07:02 AM
I take it that the sample sheets in your attachment depict the exact layout of your sheets.
I mean, data titles are on row 5 and there is nothing else above or below the data.
Is that correct?

bobby_793
04-13-2008, 07:15 AM
tstav data titles are on row 5 till below up to 2500 rows. but here i just show the example only.

lucas
04-13-2008, 07:40 AM
Threads merged.

Bobby if you wish to revive a question you should post in that thread again asking for additional help instead of starting a new, identical thread....

tstav
04-13-2008, 07:58 AM
Ok, supposing there is no data ABOVE the titles (I see four empty rows there), try the following:
Sub FilterAndCopy()
Dim lastRow As Long, lngRow As Long
Dim coll As Collection
Dim collItem As Variant
Dim copyR As Range
Application.ScreenUpdating = False
With Worksheets("Main")
If .AutoFilterMode = True Then .AutoFilterMode = False
lastRow = .Range("D" & .Rows.count).End(xlUp).Row

'Fill collection with unique Descriptions
Set coll = New Collection
On Error Resume Next
For lngRow = 6 To lastRow
coll.Add .Range("D" & lngRow).Value, .Range("D" & lngRow).Value
Next 'lngRow
If Err Then Err.Clear
On Error GoTo 0

'For each Description copy the data
For Each collItem In coll
If WorksheetExists(collItem) Then
Worksheets(collItem).UsedRange.EntireRow.Delete
'Show only this Description's data
.Range("A5").AutoFilter Field:=4, Criteria1:=collItem
Set copyR = .UsedRange
copyR.Copy Worksheets(collItem).Range("A5")
With Worksheets(collItem)
.UsedRange.Value = .UsedRange.Value
lastRow = .UsedRange.Row + .UsedRange.Rows.count - 1
.Rows(lastRow).Copy .Range("A" & lastRow + 1)
.Rows(lastRow + 1).ClearContents
.Range("E" & lastRow + 1).Value = WorksheetFunction.Sum(.Range("E6:E" & lastRow))
.Range("F" & lastRow + 1).Value = WorksheetFunction.Sum(.Range("F6:F" & lastRow))
.Range("G" & lastRow + 1).Value = WorksheetFunction.Sum(.Range("G6:G" & lastRow))
End With
'Show all data
.Range("A5").AutoFilter
Else
MsgBox "Worksheet was not found for description '" & collItem & "'"
End If
Next 'collItem
End With
Application.ScreenUpdating = True
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function WorksheetExists(ByVal strSheetName As String) As Boolean
On Error Resume Next
WorksheetExists = (Not Worksheets(strSheetName) Is Nothing)
End Function


Edit: Minor amendments to comments

tstav
04-13-2008, 08:06 AM
By the way, in your attachment file, the 'GSI ' description has a trailing blank and so the relevant 'GSI' worksheet could not be found.
I chose to pop up a message to report such cases as 'Worksheet missing'.
Of course, this could be handled otherwise.

bobby_793
04-13-2008, 08:10 AM
OK FINE I AM BACK TO MY OLD THREAD AGAIN ....SO PLS HELP ME

tstav
04-13-2008, 08:17 AM
bobby check posts#12 and #13, right above your last post

bobby_793
04-13-2008, 09:20 AM
Oh Thank you dear TSTAV really your are great it works fine with me thanks alot. Even GSI also uptodate
thanks alot

Aussiebear
04-14-2008, 01:42 AM
bobby, if this is the solution to your issue, could you please take the time to mark this thread as "Solved" by using the thread tools.