My code below:
The three codes below are the ones being called into the routine
Whenever I do i break and step through the code, i have no issues. though, it does say "can't execute in break mode" but i click out of that and it steps right through.
What's happening is my range ("M2" & lrw) is for some reason cutting from the wr wksht and pasting to my fls wksht. the error occurs for both wkbk open operations.
Any thoughts as to what's causing this?
Also if anyone wants to take a stab at condensing this, i'm all ears.
thanks
VBA Code:
Sub arrange()
'all declarations for wkshts and wbs stated at top unless stated here
Dim g1 As Range
Dim g2 As Range
Dim g3 As Range
Dim g4 As Range
Dim g5 As Range
Dim g6 As Range
Dim g7 As Range
Dim g8 As Range
Dim g9 As Range
Dim g10 As Range
Dim g11 As Range
Dim g12 As Range
Dim a1 As Range
Dim a2 As Range
Dim a3 As Range
Dim a4 As Range
Dim a5 As Range
Dim a6 As Range
Dim a7 As Range
Dim a8 As Range
Dim a9 As Range
Dim a10 As Range
Dim a11 As Range
Dim a12 As Range
Dim i As Integer
Set wb = ThisWorkbook
Set gr = wb.Worksheets("GR")
Set ah = wb.Worksheets("AH")
Set fls = wb.Worksheets("Fields")
Set wr = wb.Worksheets("Wrap")
Application.ScreenUpdating = False
With gr
lrg = .Range("A1").End(xlDown).Row
Set g1 = .Range("A2:A" & lrg)
Set g2 = .Range("V2:V" & lrg)
Set g3 = .Range("Y2:Y" & lrg)
Set g4 = .Range("L2:L" & lrg)
Set g5 = .Range("P2:P" & lrg)
Set g6 = .Range("T2:T" & lrg)
Set g7 = .Range("Z2:Z" & lrg)
Set g8 = .Range("C2:C" & lrg)
Set g9 = .Range("D2:D" & lrg)
Set g10 = .Range("AB2:AB" & lrg)
Set g11 = .Range("E2:E" & lrg)
Set g12 = .Range("AI2:AI" & lrg)
End With
With ah
lra = ah.Range("A1").End(xlDown).Row
Set a1 = .Range("A2:A" & lra)
Set a2 = .Range("H2:H" & lra)
Set a3 = .Range("I2:I" & lra)
Set a4 = .Range("AC2:AC" & lra)
Set a5 = .Range("AA2:AA" & lra)
Set a6 = .Range("Z2:Z" & lra)
Set a7 = .Range("AO2:AO" & lra)
Set a8 = .Range("D2:D" & lra)
Set a9 = .Range("C2:C" & lra)
Set a10 = .Range("G2:G" & lra)
Set a11 = .Range("F2:F" & lra)
Set a12 = .Range("AQ2:AQ" & lra)
End With
g1.Copy
wr.Range("A2").PasteSpecial Paste:=xlPasteValues
g2.Copy
wr.Range("B2").PasteSpecial Paste:=xlPasteValues
g3.Copy
wr.Range("C2").PasteSpecial Paste:=xlPasteValues
g4.Copy
wr.Range("D2").PasteSpecial Paste:=xlPasteValues
g5.Copy
wr.Range("E2").PasteSpecial Paste:=xlPasteValues
g6.Copy
wr.Range("F2").PasteSpecial Paste:=xlPasteValues
g7.Copy
wr.Range("G2").PasteSpecial Paste:=xlPasteValues
g8.Copy
wr.Range("H2").PasteSpecial Paste:=xlPasteValues
g9.Copy
wr.Range("I2").PasteSpecial Paste:=xlPasteValues
g10.Copy
wr.Range("J2").PasteSpecial Paste:=xlPasteValues
g11.Copy
wr.Range("K2").PasteSpecial Paste:=xlPasteValues
g12.Copy
wr.Range("L2").PasteSpecial Paste:=xlPasteValues
With wr
lrw = .Range("A1").End(xlDown).Row
i = 2
Do Until i = lrw + 1
Cells(i, 13).Value2 = "GR"
i = i + 1
Loop
lrw = .Range("A1").End(xlDown).Row
i = lrw + 1
End With
a1.Copy
wr.Cells(lrw + 1, "A").PasteSpecial Paste:=xlPasteValues
a2.Copy
wr.Cells(lrw + 1, "B").PasteSpecial Paste:=xlPasteValues
a3.Copy
wr.Cells(lrw + 1, "C").PasteSpecial Paste:=xlPasteValues
a4.Copy
wr.Cells(lrw + 1, "D").PasteSpecial Paste:=xlPasteValues
a5.Copy
wr.Cells(lrw + 1, "E").PasteSpecial Paste:=xlPasteValues
a6.Copy
wr.Cells(lrw + 1, "F").PasteSpecial Paste:=xlPasteValues
a7.Copy
wr.Cells(lrw + 1, "G").PasteSpecial Paste:=xlPasteValues
a8.Copy
wr.Cells(lrw + 1, "H").PasteSpecial Paste:=xlPasteValues
a9.Copy
wr.Cells(lrw + 1, "I").PasteSpecial Paste:=xlPasteValues
a10.Copy
wr.Cells(lrw + 1, "J").PasteSpecial Paste:=xlPasteValues
a11.Copy
wr.Cells(lrw + 1, "K").PasteSpecial Paste:=xlPasteValues
a12.Copy
wr.Cells(lrw + 1, "L").PasteSpecial Paste:=xlPasteValues
With wr
lrw = .Range("A1").End(xlDown).Row
Do Until i = lrw + 1
Cells(i, 13).Value2 = "AH"
i = i + 1
Loop
End With
Application.CutCopyMode = False
Call formats
If fls.Range("B10").Value2 = "N" Then
Call sendtodb
Else
Call eject
End If
Application.ScreenUpdating = True
End Sub
The three codes below are the ones being called into the routine
VBA Code:
Sub formats()
Set wb = ThisWorkbook
Set wr = wb.Worksheets("Wrap")
With wr
lrw = .Range("A1").End(xlDown).Row
.Range("B2:C" & lrw).NumberFormat = "#,##0"
.Range("D2:E" & lrw).NumberFormat = "#.00"
.Range("F2" & lrw).NumberFormat = "#"
.Range("N" & lrw).NumberFormat = "mm/dd/yy;@"
.Range("G2:N" & lrw).HorizontalAlignment = xlCenter
End With
End Sub
Sub sendtodb()
Dim nwb As Workbook
Dim dt As Worksheet
Dim lrd As Long
Set wb = ThisWorkbook
Set fls = wb.Worksheets("Fields")
Set nwb = Workbooks.Open(Filename:=fls.Range("A23").Value2 & ".xlsx")
Set wr = wb.Worksheets("Wrap")
Set dt = nwb.Worksheets("Data")
With wr
lrw = .Range("A1").End(xlDown).Row
End With
wr.Range("A2:N" & lrw).Copy
dt.Range("A2").PasteSpecial Paste:=xlPasteAll
With dt
lrd = .Range("A1").End(xlDown).Row
.Range("O2:Q2").Copy
.Range("O3:Q" & lrd).PasteSpecial Paste:=xlPasteAll
.Activate
End With
Application.CutCopyMode = False
End Sub
Sub eject()
Dim wb2 As Workbook
Dim ld As Worksheet
Dim lrl As Long
Set wb = ThisWorkbook
Set wr = wb.Worksheets("Wrap")
Set wb2 = Workbooks.Open('....file path
Set ld = wb2.Worksheets("Load")
With wr
lrw = .Range("A1").End(xlDown).Row
End With
wr.Range("A2:N" & lrw).Copy
ld.Range("A2").PasteSpecial Paste:=xlPasteAll
With ld
lrl = .Range("A1").End(xlDown).Row
.Range("O2").Copy
.Range("O3:O" & lrl).PasteSpecial Paste:=xlPasteAll
.Activate
End With
End Sub
Whenever I do i break and step through the code, i have no issues. though, it does say "can't execute in break mode" but i click out of that and it steps right through.
What's happening is my range ("M2" & lrw) is for some reason cutting from the wr wksht and pasting to my fls wksht. the error occurs for both wkbk open operations.
Any thoughts as to what's causing this?
Also if anyone wants to take a stab at condensing this, i'm all ears.
thanks