Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Help Needed...copy into new sheet based on account number

I have a weekly report that shows transactions for 7 accounts. I need to
break out the data into separate tabs based on the account number (all of
account #1's transactions in a tab, account #2 in a tab, etc). I have
written the macro to create the new sheets but I cannot figure out what the
VBA would look like for actually selecting the row(s) based on the account
number field and pasting it into a new sheet. This is going to be a variable
range report (different amount of transactions each week) so I need it to be
able to search the data, copy, and paste into the new sheets.

Any ideas???


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro Help Needed...copy into new sheet based on account number

Sub MakeTabs()

Set OldSht = ActiveSheet
With OldSht
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
'sort data
.Rows("1:" & LastRow).Sort _
key1:=.Range("A1"), _
order1:=xlAscending, _
header:=xlYes

RowCount = 2
Start = RowCount
Do While .Range("A" & RowCount) < ""
If .Range("A" & RowCount) < _
.Range("A" & (RowCount + 1)) Then

ID = .Range("A" & RowCount)
Set NewSht = Sheets.Add(after:=Sheets(Sheets.Count))
NewSht.Name = ID
'copy header row
.Rows(1).Copy Destination:=NewSht.Rows(1)
.Rows(Start & ":" & RowCount).Copy _
Destination:=NewSht.Rows(2)
Start = RowCount + 1
End If
RowCount = RowCount + 1
Loop
End With

End Sub


"Have_Data_Will_Travel" wrote:

I have a weekly report that shows transactions for 7 accounts. I need to
break out the data into separate tabs based on the account number (all of
account #1's transactions in a tab, account #2 in a tab, etc). I have
written the macro to create the new sheets but I cannot figure out what the
VBA would look like for actually selecting the row(s) based on the account
number field and pasting it into a new sheet. This is going to be a variable
range report (different amount of transactions each week) so I need it to be
able to search the data, copy, and paste into the new sheets.

Any ideas???


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Macro Help Needed...copy into new sheet based on account numbe

WOW! Perfect...thank you! I'm just beginning to really learn VBA and this
was a huge help

"HDWT"


"joel" wrote:

Sub MakeTabs()

Set OldSht = ActiveSheet
With OldSht
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
'sort data
.Rows("1:" & LastRow).Sort _
key1:=.Range("A1"), _
order1:=xlAscending, _
header:=xlYes

RowCount = 2
Start = RowCount
Do While .Range("A" & RowCount) < ""
If .Range("A" & RowCount) < _
.Range("A" & (RowCount + 1)) Then

ID = .Range("A" & RowCount)
Set NewSht = Sheets.Add(after:=Sheets(Sheets.Count))
NewSht.Name = ID
'copy header row
.Rows(1).Copy Destination:=NewSht.Rows(1)
.Rows(Start & ":" & RowCount).Copy _
Destination:=NewSht.Rows(2)
Start = RowCount + 1
End If
RowCount = RowCount + 1
Loop
End With

End Sub


"Have_Data_Will_Travel" wrote:

I have a weekly report that shows transactions for 7 accounts. I need to
break out the data into separate tabs based on the account number (all of
account #1's transactions in a tab, account #2 in a tab, etc). I have
written the macro to create the new sheets but I cannot figure out what the
VBA would look like for actually selecting the row(s) based on the account
number field and pasting it into a new sheet. This is going to be a variable
range report (different amount of transactions each week) so I need it to be
able to search the data, copy, and paste into the new sheets.

Any ideas???


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro Help Needed...copy into new sheet based on account numbe

You may want to change this line

from
Set OldSht = ActiveSheet
to
Set OldSht = Sheets("Sheet1")


"Have_Data_Will_Travel" wrote:

WOW! Perfect...thank you! I'm just beginning to really learn VBA and this
was a huge help

"HDWT"


"joel" wrote:

Sub MakeTabs()

Set OldSht = ActiveSheet
With OldSht
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
'sort data
.Rows("1:" & LastRow).Sort _
key1:=.Range("A1"), _
order1:=xlAscending, _
header:=xlYes

RowCount = 2
Start = RowCount
Do While .Range("A" & RowCount) < ""
If .Range("A" & RowCount) < _
.Range("A" & (RowCount + 1)) Then

ID = .Range("A" & RowCount)
Set NewSht = Sheets.Add(after:=Sheets(Sheets.Count))
NewSht.Name = ID
'copy header row
.Rows(1).Copy Destination:=NewSht.Rows(1)
.Rows(Start & ":" & RowCount).Copy _
Destination:=NewSht.Rows(2)
Start = RowCount + 1
End If
RowCount = RowCount + 1
Loop
End With

End Sub


"Have_Data_Will_Travel" wrote:

I have a weekly report that shows transactions for 7 accounts. I need to
break out the data into separate tabs based on the account number (all of
account #1's transactions in a tab, account #2 in a tab, etc). I have
written the macro to create the new sheets but I cannot figure out what the
VBA would look like for actually selecting the row(s) based on the account
number field and pasting it into a new sheet. This is going to be a variable
range report (different amount of transactions each week) so I need it to be
able to search the data, copy, and paste into the new sheets.

Any ideas???


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
Insert Name based on the account number Vic Excel Discussion (Misc queries) 2 June 22nd 09 04:21 PM
Macro to copy and paste to another sheet, based on if-then-else ABlevins Excel Programming 0 May 19th 08 02:09 PM
VAB to copy cell values into new Sheet, Overwrite if needed and based off of Cell Value in a column gumby Excel Programming 4 July 14th 07 01:55 AM
MACRO - copy rows based on value in column to another sheet Michael A Excel Discussion (Misc queries) 1 March 5th 05 02:15 AM
MACRO - copy rows based on value in column to another sheet Mike Excel Programming 2 March 5th 05 12:21 AM


All times are GMT +1. The time now is 04:49 AM.

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"