Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Insert Name based on the account number | Excel Discussion (Misc queries) | |||
Macro to copy and paste to another sheet, based on if-then-else | Excel Programming | |||
VAB to copy cell values into new Sheet, Overwrite if needed and based off of Cell Value in a column | Excel Programming | |||
MACRO - copy rows based on value in column to another sheet | Excel Discussion (Misc queries) | |||
MACRO - copy rows based on value in column to another sheet | Excel Programming |