Alex O
Active Member
- Joined
- Mar 16, 2009
- Messages
- 345
- Office Version
- 365
- Platform
- 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
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