Copy Macro to New Sheet

Alex O

Active Member
Joined
Mar 16, 2009
Messages
345
Office Version
  1. 365
Platform
  1. Windows
This question may be totally off the wall, but is it possible to have a macro copied to a new workbook as part of a routine? I.E. After running my NewUploadFile routine, I want the subroutine myDeleteRows to be in the new workbook.

Sub NewUploadFile()
Dim wb As Workbook
Set wb = Workbooks.Add
'copy and paste
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy
With wb.Sheets("Sheet1")
.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
.Range("A1").PasteSpecial Paste:=xlPasteFormats
.Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
End With
Set wb = Nothing
End Sub

Sub myDeleteRows()

Dim MyCol As String
Dim MyVal As Variant
Dim i As Integer

MyCol = InputBox("column to look through", "Column Search", "A")
MyVal = InputBox("Value to look for", "search value", 0)
For i = 1 To Range(MyCol & "65536").End(xlUp).Row Step 1
If Application.WorksheetFunction.CountIf(Range("A" & i & ":AZ" & i), MyVal) > 0 Then
Range("A" & i).EntireRow.Delete
End If
Next i

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Good Information....thanks. It's probably a bit advanced for me, but I may be able to figure it out....
 
Upvote 0
Be aware, if you are going to issue this to other users, that automated changes to macros (inserts edits deletes) are often seen as Virus activity by most security systems.

Which maybe fine for you, but a couple months down the line and a couple of user changes later will be very disconcerting.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

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