For without Next - no knowledge of coding

MDMitch

New Member
Joined
Feb 25, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Good morning Guys,
I Have zero knowledge about coding but for my job I get questions about improving stuff.

I have found many things that I copy pasted and eventually got what I wanted except my file would save "In a specific folder on my computer" where I wanted to save the file in the General origin of the excel file no matter what computer it was in. I found a code that I think would do that so I removed the last part of the code and placed the new one in.

Now I am getting this Next for Without.
Can anyone look at the thing and fix it ?
I think the error must be in the last 10 lines as everything was working fine before I got there.

VBA Code:
Sub Test()
'
' Test Macro
'

'
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("I:I").Select
    Selection.Delete Shift:=xlToLeft
    Columns("G:G").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("D:D").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Cut
    Columns("C:C").Select
    Selection.Insert Shift:=xlToRight
    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("AxTable1[[#Headers],[Column1]]").Select
    ActiveCell.FormulaR1C1 = "Location"
    Columns("E:E").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("AxTable1[[#Headers],[Column1]]").Select
    ActiveCell.FormulaR1C1 = "Sub Location"
    Range("AxTable1[[#Headers],[Quantity]]").Select
    Selection.Copy
    Range("H1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Date"
    Range("D2").Select
    Application.CutCopyMode = False
    Range("B1").Select
    Columns("H:H").Select
    Selection.NumberFormat = "m/d/yyyy"
    Range("H2").Select
    ActiveCell.FormulaR1C1 = "=IF(COUNTA(R2C[-1]:R100C[-1])>0,TODAY(),0)"
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "PO"
 Range("A1").Select
    ActiveCell.FormulaR1C1 = "PO"
  
   curUser = ActiveCell.Value
 msg = InputBox("Please enter PO # for: " & curUser, "PO")
 If msg <> "" Then
 Range("A2").Select
 ActiveCell.Value = msg
    Range("A2").Select
    Selection.AutoFill Destination:=Range("A2:A100"), Type:=xlFillDefault
    Range("A2:A100").Select
ThisWorkbook.VBProject.VBE.MainWindow.Visible = False
End If

   Columns("B:B").Select
   Selection.SpecialCells(xlCellTypeBlanks).Select
   Selection.EntireRow.Delete
  
   Range("A2:I2").Select
   ActiveWindow.SmallScroll Down:=81
    Range("A2:I100").Select
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-12
    Columns("H:H").ColumnWidth = 10.09
    Columns("I:I").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    Cells.Select
    Selection.NumberFormat = "General"
    ActiveWindow.SmallScroll Down:=200
    Dim Fpath As String
    Fpath = Application.ActiveWorkbook.Path
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each WS In ThisWorkbook.Sheets
    WS.Copy
    Application.ActiveWorkbook.SaveAs Filename:=Fpath & "\" & WS.Name & ".xlsx", FileFormat:=xlText, CreateBackup:=False
    Range("D10").Select
    ActiveWindow.Close
     
     
End Sub
 
Last edited by a moderator:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If it's not a typo, just at the end of the macro you are missing a: Next WS since a couple of rows above you have a: For Each WS ... that needs to be 'closed'.
 
Upvote 0
If it's not a typo, just at the end of the macro you are missing a: Next WS since a couple of rows above you have a: For Each WS ... that needs to be 'closed'.
Thank you,
I am now getting an error Object required
Then it points to
VBA Code:
Application.ActiveWorkbook.SaveAs Filename:=Fpath & "\" & WS.Name & ".xlsx", FileFormat:=xlText, CreateBackup:=False
 
Upvote 0
No idea, works for me, but, just to anticipate the next problem, if the extension will be .xlsx, why are you indicating xlText as file format ?
If it's going to be saved as Excel file .xlsx then file format should be: xlWorkbookDefault elsewise, if it's going to be saved as a text file the extension should be: .txt
 
Upvote 0
Solution
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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