VBA Help

njlevi49

Board Regular
Joined
Sep 20, 2009
Messages
51
I need help with VBA as this is my first time using it. I would like to copy and paste a1:ab14 to another worksheet but I need columns b, d, p, r removed also only rows with p in column A to paste with no blank rows showing, any help or ideas would be greatly appreciated.


ABCDEFGHLJKLMNOPQRSTUVWXYZAAAB
1 Gross 123456789 101112131415161718
2 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Front Nine 375264891 41394Back Nine 239758641
3 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Barker, Steve254443453436p41394Barker, Steve254435354437
4p<st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Batcheider, Jason254443453436 41394Batcheider, Jason254435354437
5 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Budd, Jerry 354443453436 41394Budd, Jerry 354435354437
6 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Campau, Chad254443453436 41394Campau, Chad254435354437
7 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Coates, Brian365444345338p41394Coates, Brian354435354437
8p<st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Conway, Casey254443453436 41394Conway, Casey254435354437
9 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Curry, Claude254443453436 41394Curry, Claude254435354437
10 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Dattilo, Mike254443453436 41394Dattilo, Mike254435354437
11p<st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Daugherty, Pat354443453436 41394Daugherty, Pat354435354437
12 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Dennis, Brad254444453437 41394Dennis, Brad254435354437
13 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Dougherty Jack254443453436 41394Dougherty Jack254435354437
14 <st1:date ls="trans" Month="04" Day="23" Year="13">04/23/13</st1:date> Emeott,Mark 254443453436 41394Emeott,Mark 254435354437

<colgroup><col style="width: 19pt; mso-width-source: userset; mso-width-alt: 914;" width="25"> <col style="width: 12pt; mso-width-source: userset; mso-width-alt: 585;" width="16"> <col style="width: 46pt; mso-width-source: userset; mso-width-alt: 2230;" width="61"> <col style="width: 69pt; mso-width-source: userset; mso-width-alt: 3364;" width="92"> <col style="width: 26pt; mso-width-source: userset; mso-width-alt: 1243;" width="34"> <col style="width: 20pt; mso-width-source: userset; mso-width-alt: 950;" span="10" width="26"> <col style="width: 17pt; mso-width-source: userset; mso-width-alt: 804;" width="22"> <col style="width: 37pt; mso-width-source: userset; mso-width-alt: 1792;" width="49"> <col style="width: 69pt; mso-width-source: userset; mso-width-alt: 3364;" width="92"> <col style="width: 20pt; mso-width-source: userset; mso-width-alt: 950;" width="26"> <col style="width: 20pt; mso-width-source: userset; mso-width-alt: 950;" span="10" width="26"> <tbody>
</tbody>
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi

Try this:

Code:
Sub CopyData()
Dim rData As Range
Dim wsNew As Worksheet

ActiveSheet.AutoFilterMode = False
Set rData = Range("A1:Ab14")
rData.AutoFilter field:=1, Criteria1:="p"
.AutoFilter.Range.Copy
Set wsNew = Sheets.Add
With wsNew
    .Range("A1").PasteSpecial
    .Range("b:b,d:d,p:p,r:r").Delete
End With


End Sub

Place it in a standard module and run it with the sheet containing your data active (ie visible on your Excel screen).
 
Upvote 0
Hi

Try this:

Code:
Sub CopyData()
Dim rData As Range
Dim wsNew As Worksheet

ActiveSheet.AutoFilterMode = False
Set rData = Range("A1:Ab14")
rData.AutoFilter field:=1, Criteria1:="p"
.AutoFilter.Range.Copy
Set wsNew = Sheets.Add
With wsNew
    .Range("A1").PasteSpecial
    .Range("b:b,d:d,p:p,r:r").Delete
End With


End Sub

Place it in a standard module and run it with the sheet containing your data active (ie visible on your Excel screen).

Sub CopyData()
Dim rData As Range
Dim wsNew As Worksheet
ActiveSheet.AutoFilterMode = False
Set rData = Range("a1:ab14")
rData.AutoFilter field:=1, Criteria1:="p"
.AutoFilter.Range.Copy (I get invalid or unqualified reference) with .AutoFilter highlighted
Set wsNew = Sheets.Add
With wsNew
.Range("A1").PasteSpecial
.Range("b:b,d:d,p:p,r:r").Delete
End With
End Sub

See above for the issue not sure how to fix it if I remove the period from .AutoFilter I get a run-time error 424
 
Upvote 0
Sub CopyData()
Dim rData As Range
Dim wsNew As Worksheet
ActiveSheet.AutoFilterMode = False
Set rData = Range("a1:ab14")
rData.AutoFilter field:=1, Criteria1:="p"
.AutoFilter.Range.Copy (I get invalid or unqualified reference) with .AutoFilter highlighted
Set wsNew = Sheets.Add
With wsNew
.Range("A1").PasteSpecial
.Range("b:b,d:d,p:p,r:r").Delete
End With
End Sub

See above for the issue not sure how to fix it if I remove the period from .AutoFilter I get a run-time error 424
 
Upvote 0
Apologies - I thought I had corrected that omission. The code should be:

Code:
Sub CopyData()
Dim rData As Range
Dim wsNew As Worksheet

ActiveSheet.AutoFilterMode = False
Set rData = Range("A1:Ab14")
rData.AutoFilter field:=1, Criteria1:="p"
Activesheet.AutoFilter.Range.Copy
Set wsNew = Sheets.Add
With wsNew
    .Range("A1").PasteSpecial
    .Range("b:b,d:d,p:p,r:r").Delete
End With


End Sub
 
Upvote 0
Thanks that worked the only other problem with this is I just need the values not the formulas I am not sure how or where I would place the Pastespecial Operation Values. do you also know a book that would provide mw with different VBA samples for all occasions? Again Thank you
 
Upvote 0
Code:
.Range("A1").PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,888
Members
449,411
Latest member
AppellatePerson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top