I have a code where I'm basically looping through and copying data from one excel sheet and pasting it into my active workbook. However, the current way I have my code written I'm using the Exit Sub statement and everything below that statement will not execute. Is there an alternative I can use to the Exit Sub which will still work with my current code structure?
Dim ws As Worksheet
Dim Prefix As String, Suffix As String
Dim ROfs As Integer, COfs As Integer
Dim Source As Range, Dest As Range, This As Range
Set ws = ThisWorkbook.Worksheets("Sheet1")
With ws
'The formula becomes Prefix & Source.Address & Suffix
Prefix = "='C:x\xx\[Workbook1.xls]Worksheet1'!"
Suffix = "/1000"
'Direction for the next Source cell
COfs = -1
'Destination cells
Set Dest = .Range("G8:G12")
Set Source = Range("G8")
GoSub Fill
Set Dest = .Range("G13:G17")
Set Source = Range("G9")
GoSub Fill
Suffix = ""
Set Dest = .Range("G3:G7")
Set Source = Range("G10")
GoSub Fill
Suffix = "/1000"
Set Dest = .Range("G26:G30")
Set Source = Range("G35")
GoSub Fill
Suffix = ""
Set Dest = .Range("G21:G25")
Set Source = Range("G37")
GoSub Fill
Suffix = "/1000"
Set Dest = .Range("G31:G35")
Set Source = Range("G36")
GoSub Fill
End With
Exit Sub
Fill:
For Each This In Dest
This.Formula = Prefix & Source.Address(0, 0) & Suffix
Set Source = Source.Offset(ROfs, COfs)
Next
Dest.Value = Dest.Value
Return
'''Everything Below Does Not Execute'''
ws.Columns("C").EntireColumn.Delete
Dim strFormulas As Variant
With ws
strFormulas = "=(F3-C3)"
.Range("G3:G17").Formula = strFormulas
.Range("G3:G17").FillDown
End With
End Sub
Dest.Value = Dest.Value?GoSubis a hangover from a much earlier era of Basic. Don't use it. Ever.