VBA Code Editing Help Requested

Justinian

Well-known Member
Joined
Aug 9, 2009
Messages
1,557
Office Version
  1. 365
Platform
  1. Windows
Every morning, I copy data from an external source and paste into Excel. This gives me work order information from the previous day except for one problem: I do not need the pasted data in column G. Starting from a blank worksheet, I run this code to paste the data:

Sub Paste_Copied_Data()

Range("A1").Select
ActiveSheet.paste
Range("L18").Select

End Sub


When I then try to remove the pasted data in column G with the following macro, all my data gets deleted instead of just column G:

Sub Macro1()
'
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft

End Sub

How do I paste my data and then have the code delete column G without deleting anything else? What am I doing wrong?
 
Use the CALL procedure

Code:
SUB Cpy_Pste()
CALL  ModuleName.Paste_Copied_Data
CALL ModuleName.[COLOR=#333333]Macro1[/COLOR]
End Sub

I do not want macro 1 in here. I just recorded it so I could get the code to delete column G.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Just replace this line
Code:
Worksheets("Macro").Range("G1").Select
with
Code:
Worksheets("Macro").Range("G:G").Delete
In your Remove_Unwanted macro
 
Upvote 0
Wow, the answer was staring me in the face and I missed it!

Thank you!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
I spoke too soon. It worked last night but now it will not because when I run the "Remove Unwanted" macro, I get a message that says "this operation will casue some merged cells to unmerge," but I have no merged cells in here. I do not understand why it worked last night but not now.
 
Upvote 0
Ok, I see that now but when I highlight column G and delete manually, it deletes with no problems. Why will it not perform the same way when I run the macro? How do I solve the problem?
 
Upvote 0
The macro works fine for me. Can you upload another file, where it's causing problems?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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