Solved

Excel 2007 - VBA Help.  Copy Rows between Tabs

Posted on 2012-04-01
10
353 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
 
LVL 33

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 33

Accepted Solution

by:
Norie earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now