Running a macro from a home sheet?

Joshua88

New Member
Joined
Apr 27, 2018
Messages
20
Hello all I'm new here, and seem to stuck on some code, I have a sheet called home with my macro buttons, I also have a hidden sheets called datadump3, that I use to
import data from another work book, that all works fine but I am having an issue with the last part were I am deleting rows that contain Do Not Cut, on datadump3, when I'm on the home sheet and click the macro button I get an error (select method of range class failed), but if I select on the datadump3 sheet and make it the active sheet and run the code from vb it runs fine, I think I need to specify which sheet it should be working on? not sure any help would be great hope I posted this right thank you

Code:
   Sub GtSt()
'
' GtSt Macro
'
'===================================================
'define the variables
On Error GoTo Errmsg
Errmsg:
    If Err.Number = 9 Then
        MsgBox "The workbook named cutlist is not open or has been renamed. Click ok then in the eCabinets cut list click on export cut list to excel and select open.", vbCritical
        Exit Sub
 
    End If
Application.ScreenUpdating = False
Dim Home As Worksheet
Set Home = ThisWorkbook.Sheets("Home")
Dim eCabCl As Workbook
Dim SheSts As Worksheet
Dim Ddump3 As Worksheet
Set eCabCl = Workbooks("cutlist.xls")
Set SheSts = eCabCl.Sheets("SheetStockSummary")
Set Ddump3 = ThisWorkbook.Sheets("DataDump3")
Dim col As Variant
Dim isnum As Boolean
'===================================================
'Import theBuild in house Drawer Box Listing Cutlist from ecabinets into the data dump worksheet
'Clear existing data
Ddump3.UsedRange.ClearContents
SheSts.UsedRange.Copy Destination:=Ddump3.Range("A1")
'Convert numbers stored as text to numbers
Ddump3.Cells.Replace What:="""", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
     Ddump3.Range("H:H").WrapText = False
'will not wrap test
Ddump3.UsedRange.WrapText = False
'Now loop thru the columns and use text to columns to convert the numbers that are store as text to numbers
For Each col In Ddump3.Columns
    'exit the loop if there is no data in the current column header
    If Ddump3.Cells(1, col.Column) = "" Then
        Exit For
    Else
      'Or else just do text to columns to convert the numbers stored as text to numbers notice every thing is set to false
        Ddump3.Columns(col.Column).TextToColumns Destination:=Cells(1, col.Column), DataType:=xlDelimited, _
        TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, OtherChar _
        :="-", FieldInfo:=Array(Array(1, 1)), TrailingMinusNumbers:=False
        isnum = IsNumeric(Ddump3.Cells(2, col.Column))
            If isnum = True Then
                If Ddump3.Cells(1, col.Column) = "Qty" Then
                    Ddump3.Columns(col.Column).NumberFormat = "0"
                Else
                    Ddump3.Columns(col.Column).NumberFormat = "0.00"
                End If
              End If
  
    End If
Next col
'Call RemoveLines
'============================================================================================================
'delet do not cut
Worksheets("DataDump3").Range("B1").Select
For Counter = 1 To 12
If ActiveCell.Value Like "*Do Not Cut*" Then
ActiveCell.EntireRow.Delete ' Delete Row
Else
ActiveCell.Offset(1, 0).Select ' Move down a row
End If
Next
Application.ScreenUpdating = True

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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