Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel 2007 - VBA Help.  Copy Rows between Tabs

Posted on 2012-04-01
10
Medium Priority
?
363 Views
Last Modified: 2012-06-21
OK.  Checkboxes didn't work as it just crashes my Excel.  So trying again.  So here is what I need.

Have a spreadsheet (Attached).  This is only two tabs of the actual spreadsheet but hoping this can convert easily.  Tabs are Retrieval and Master.  Rows 1-15 are heading rows and should never be altered or moved or changed in any way.

Also why it asks for vba password is beyond me.  This is a brand new Excel sheet from scratch.  I never set a password.

If possible can we name modules something related to these buttons/macros?  

I really appreciate the help.  I tried the 'Check Box' way via another post and it just crashed my Excel as the file grew too big.  

I put notes on each tab in the file for details.  I will award a ton of points for this on separate questions as we go down each.
EE-Template-New.xlsm
0
Comment
Question by:elwayisgod
  • 6
  • 2
  • 2
10 Comments
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37793679
@elwayisgod :

There are 2 different kinds of buttons in Excel:
1) "ActiveX"-Buttons and
2) "Form"-Buttons

Because the three buttons in your Excel file were "Form-Buttons", I inserted three
"ActiveX-Buttons", and if you insert some code, your code should work. See attached file ...
EE-Template-New.xlsm
0
 

Author Comment

by:elwayisgod
ID: 37793684
OK.. I have no idea what Active X means.  I need help with the code to perform the tasks too.  I'm not a VBA person at all.  I can attach the code to a button and do some minor tinkering but cannot actually write the code too.

I can't even get into the Visual Basic editor?  It asks for a password.  I never even set one.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37793694
>>I can't even get into the Visual Basic editor?
When Excel is running press [ALT + F11]. Then you can insert your VBA code.

>>It asks for a password.
On my computer it doesn't ask for a password, and I can insert some code.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Expert Comment

by:Norie
ID: 37793701
This code will copy the records from Retrieval as indicated, it uses Sheet3 as a kind of 'workings' sheet.
Option Explicit

Sub CopyFromRetrieval()
Dim rngData As Range
Dim rngResult As Range
Dim rngHeaders As Range
Dim NoCols As Long
Dim rngDst As Range
Dim rngCrit As Range
Dim LastRow As Long

    LastRow = Worksheets("Retrieval").Range("B" & Rows.Count).End(xlUp).Row

    Set rngData = Worksheets("Retrieval").Range("A14:U1" & LastRow)
    
    Set rngHeaders = rngData.Rows(1)
    
    NoCols = rngData.Columns.Count
    
    rngHeaders.Cells(1, 1).Value = "Field1"
    
    rngData.Cells(1, 1).AutoFill rngHeaders.Rows(1), xlFillDefault
    
    Set rngCrit = Worksheets("Sheet3").Range("A1:A2")
    
    rngCrit.Value = Application.Transpose(Array("Field1", "Copy"))
    
    Set rngDst = Worksheets("Master").Range("B" & Rows.Count).End(xlUp).Offset(1, -1)
    
    rngData.AdvancedFilter xlFilterCopy, rngCrit, rngCrit.Cells(1, 1).Offset(, 2), True
    
    rngHeaders.ClearContents
    
    rngCrit.Resize(, 2).EntireColumn.Delete
    
    LastRow = Worksheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
    
    Set rngResult = Worksheets("Sheet3").Range("A2:U" & LastRow)
    
    rngResult.Copy
    
    rngDst.PasteSpecial xlPasteValues
    
    rngResult.EntireColumn.Clear
    
    rngDst.EntireColumn.Clear
    
    Application.CutCopyMode = False
    
End Sub

Open in new window


If you right click one of the buttons, select Assign Macro.. you can assign this sub to the button's click event.

I've done that with the Copy to Master tab button in the file attached.

Not sure what the other 2 buttons are meant to do.
EE-Template-NewV2.xlsm
0
 

Author Comment

by:elwayisgod
ID: 37793736
This looks pretty good on the copy.  A few things.  Can it clear the 'Master' tab first?  That way everytime they hit the button, it's a fresh set of rows over there? Thats all I can think of on this button.  After we fix this can we move to the other buttons?
0
 

Author Comment

by:elwayisgod
ID: 37793748
I need a drop down box in Column A for Rows 15 to 3014.  Choices are 'Copy' and NULL or Blank.  That way only the ones with 'Copy' get copied when the button is pressed.

Also when I set one as Copy can it apply the shading like in the example?  There's potentially thousands of rows and shading the 'Copy' ones will help?

I can post new questions if you want more points.
0
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 37793758
Here's an update version that removes the existing data in the Master sheet.

As for the other buttons/questions, I suppose it's up to you - not sure if there any rules/etiquette.
EE-Template-NewV3.xlsm
0
 

Author Comment

by:elwayisgod
ID: 37793782
Excellent.  I'll post new question and will award another 500 pts.  You willing to keep helping me.  Only a few more to do.
0
 

Author Closing Comment

by:elwayisgod
ID: 37793784
Perfect
0
 

Author Comment

by:elwayisgod
ID: 37793798
New question is posted.  I appreciate help
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question