Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. Sub Installed_Piles()
  2. '
  3. ' Installed_Piles Macro
  4. '
  5. 'Sets some varibles
  6.  
  7. Dim nwb As Workbook
  8. Dim nws As Worksheet
  9. Dim rng As Range
  10. Dim nrng As Range
  11. Dim i As Integer
  12. Dim j As Integer
  13.  
  14. 'creates a new workbook and sets varible values
  15.  
  16. Set nwb = Workbooks.Add
  17. Set nws = nwb.Sheets("Sheet1")
  18. Set nrng = nws.Range("a1")
  19.  
  20. 'Clear filters from Data, set rng range for copying to new worksheet
  21.  
  22. Fclear Data
  23. 'Data.Range("$A$6:$D$6").AutoFilter Field:=19, Criteria1:="<>"
  24. Set rng = Get_Data(Data, "A6", "S6", 19, "<>")
  25. i = rng.Rows.Count
  26. j = rng.Columns.Count
  27.  
  28. 'Resize new worksheet to accept Data
  29.  
  30. Set nrng = nrng.Resize(i, j)
  31.  
  32. 'Copy values only over, removes unnecessary data, sets date format
  33.  
  34. nrng.Value = rng.Value
  35. nrng.Columns("E:R").Delete
  36. nrng.Columns("E:E").NumberFormat = "mm/dd/yyyy"
  37.  
  38. 'Save and exit new worksheet
  39.  
  40. ChDir fpath & "\Global Mapper"
  41. Application.DisplayAlerts = False
  42. nwb.SaveAs Filename:= _
  43. fpath & "\Global Mapper\Installed Piles.csv" _
  44. , FileFormat:=xlCSV, CreateBackup:=False
  45. nwb.Close SaveChanges:=True
  46. Fclear Data
  47.  
  48. End Sub
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. Function Get_Data(ws As Worksheet, Fc As String, Lc As String, i As Integer, c As String) As Range
  57.  
  58. 'this function is meant to accept a header range with filter criteria, it then takes that range and filters the data.
  59. 'this filtered data is then suppose to be sent out by the function which includes the header and all visible data.
  60. 'figured this would deal with zero visible data as well instead of having to search for the first visible cell.
  61.  
  62. Dim rg As Range
  63.  
  64. Set rg = ws.Range(Fc & ":" & Lc)
  65. With rg
  66. .AutoFilter field:=i, Criteria1:=c
  67. Get_Data = .Range.SpecialCells(xlCellTypeVisible)
  68. End With
  69.  
  70.  
  71.  
  72. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement