• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

Excel 2007 - VBA Help. Copy Rows between Tabs

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
elwayisgod
Asked:
elwayisgod
  • 6
  • 2
  • 2
1 Solution
 
vb_elmarCommented:
@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
 
elwayisgodAuthor Commented:
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
 
vb_elmarCommented:
>>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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
NorieVBA ExpertCommented:
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
 
elwayisgodAuthor Commented:
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
 
elwayisgodAuthor Commented:
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
 
NorieVBA ExpertCommented:
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
 
elwayisgodAuthor Commented:
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
 
elwayisgodAuthor Commented:
Perfect
0
 
elwayisgodAuthor Commented:
New question is posted.  I appreciate help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 6
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now