Hi!
I need help with some of my coding.
I cant seem to get the saveAS function to work inside a do while loop.
It works fine outside the loop.
When its inside the loop it keeps saving the same file and wont exit the saveAS and go to the next step.
The saveAS funcion is in Sub "Spara" wich im calling above the loop
This is the saveAS sub
I need help with some of my coding.
I cant seem to get the saveAS function to work inside a do while loop.
It works fine outside the loop.
When its inside the loop it keeps saving the same file and wont exit the saveAS and go to the next step.
VBA Code:
Sub test()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("LS")
Dim ws2 As Worksheet
Set ws2 = ThisWorkbook.Worksheets("Sheet1")
i = 2
y = 5
x = 7
Uo1 = 5
AntLas = 7
Kund1 = 1
ws2.Range("A12:AFP20").ClearContents
Do Until ws.Range("B" & i) = ""
If ws.Range("B" & i) = ws.Range("B" & i + 1) And ws.Range("A" & i) = ws.Range("A" & i + 1) Then
Cells(8, y) = ""
Cells(8, x) = ""
UO = ws.Range("A" & i)
LASS = ws.Range("B" & i)
Kund = ws.Range("E" & i)
antal2 = ws.Range("D" & i + 1)
ws2.Cells(8, Uo1) = UO
ws2.Cells(8, AntLas) = LASS
ws2.Cells(12, Kund1) = Kund
ws2.Cells(12 + 1, Kund1) = Kund2
i = i + 1
If ws.Range("B" & i) = ws.Range("B" & i + 1) Then
Kund3 = ws.Range("E" & i + 1)
ws2.Cells(12 + 2, Kund1) = Kund3
i = i + 1
End If
If ws.Range("B" & i) = ws.Range("B" & i + 1) Then
Kund4 = ws.Range("E" & i + 1)
ws2.Cells(12 + 3, Kund1) = Kund4
i = i + 1
End If
If ws.Range("B" & i) = ws.Range("B" & i + 1) Then
antal5 = ws.Range("D" & i + 1)
ws2.Cells(12 + 4, AntLas) = antal5
i = i + 1
End If
If ws.Range("B" & i) = ws.Range("B" & i + 1) Then
antal6 = ws.Range("D" & i + 1)
ws2.Cells(12 + 5, AntLas) = antal6
i = i + 1
End If
Else
Cells(8, y) = ""
Cells(8, x) = ""
UO = ws.Range("A" & i)
LASS = ws.Range("B" & i)
ws2.Cells(8, Uo1) = UO
ws2.Cells(8, AntLas) = LASS
End If
'Uo1 = Uo1 + 9
'AntLas = AntLas + 9
'Kund1 = Kund1 + 9
'i = i + 1
'y = y + 9
'x = x + 9
Call spara
Loop
End Sub
The saveAS funcion is in Sub "Spara" wich im calling above the loop
This is the saveAS sub
VBA Code:
Vecka = Range("B8").Value
UO = Range("E8").Value
LASS = Range("G8").Value
Set wb = Workbooks.Add
ThisWorkbook.Activate
ActiveSheet.Copy Before:=wb.Sheets(1)
wb.Activate
wb.SaveAs "c:\users\name\folder\" & Vecka & "-" & UO & "-" & LASS & "-" & Format(Date, "yyyymmdd") & ".xlsx"
wb.Close