My code is:

Public Sub valve_exersize_t1()
    
    d = Now()
    nm = (Month(d)) - 1
    pm = (Month(d)) - 2
    y = Year(d)
    py = Year(d)
    
    MsgBox d & " " & nm & " " & pm & " " & y
    
    If nm <= 0 Then
    nm = 12
    y = y - 1
    
    ElseIf nm = 1 Then
    pm = 12
    py = py - 1
    
    End If
    
  
    Filename = ("W:\ValveEx\XLS\" & "for_macro_copy_test" & ".xlsx")
    Workbooks.Open (Filename)
   
   Workbooks("for_macro_copy_test").Worksheets("sheet1").Activate
    MsgBox "activate ran"
    ActiveWorkbook.Worksheets("sheet1").Name = nm & "_" & y
   
    Workbooks("macro_enabled_all_valve_ex.xlsm").Worksheets("Sheet1").Activate
    
   
    Workbooks("for_macro_copy_test").Worksheets(nm & "_" & y).Copy After:=ActiveWorkbook.Worksheets("Sheet1")
    Workbooks("for_macro_copy_test").Close SaveChanges:=False
    
    
    
    Workbooks("macro_enabled_all_valve_ex.xlsm").Sheets(nm & "_" & y).Activate
    
    x = 1
    e = 17
    l = ActiveSheet.Rows.Count
    'l = ActiveSheet.Cells(.Row.Count, e).End(xlUp).Row
    'v = ActiveSheet.Cells(.column.Count, 1).End(xlUp).column
    Dim c As Range
    
    a = ActiveSheet.ActiveCell.Column
    MsgBox a
     
    ActiveSheet.Range("A1").Select
   
    
    Do While ActiveCell.Value <> "stop"
    MsgBox "loop ran"
    
   If IsEmpty(Cells(ActiveCell.Row, 1)) And IsEmpty(ActiveCell) And (ActiveCell.Column) < e Then
        ActiveCell.Offset(0, 1).Select
        
    ElseIf IsEmpty(Cells(ActiveCell.Row, 1)) And IsEmpty(ActiveCell) And (ActiveCell.Column) >= e Then
        ActiveCell.Offset(1, 0).Select
        x = x + 1
        
    ElseIf IsEmpty(Cells(ActiveCell.Row, 1)) And Not IsEmpty(ActiveCell) Then
        ActiveCell.Offset(-x, x) = ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
        x = x + 1

    ElseIf Not IsEmpty(Cells(ActiveCell.Row, 1)) Then
        ActiveCell.Offset(1, 0).Select
        x = 1
        
    End If

Loop
  
 Range("A1").Select

 
 
For r = 0 To l


  If IsEmpty(Cells(ActiveCell.Row, 1)) Then
     Rows(ActiveCell.Row).EntireRow.Delete
     
    Else
     ActiveCell.Offset(1, 0).Select
     
     End If
     
Next r

Range("A1").Select

For Each c In ActiveSheet.Range("A1:AA1")

'text format
If ActiveCell = "WOID" Or ActiveCell = "DESCRIPT" Or ActiveCell = "INITIATED" Or ActiveCell = "Location" Or ActiveCell = "WOCLOSE" Or ActiveCell = "WOCATEG" Or ActiveCell = "UNATTAC" Or ActiveCell = "Status" Or ActiveCell = "APPLYTOE" Or ActiveCell = "WOADDR" Or ActiveCell = "PROJECT" Or ActiveCell = "REMARKS" Or ActiveCell = "OPERATION METHO" Or ActiveCell = "DELAYS" Or ActiveCell = "FACILITYID" Or ActiveCell = "WAS THE VALVE WH" Then
Columns(ActiveCell.Column).Select
Selection.NumberFormat = "@"

'number format
ElseIf ActiveCell = "x" Or ActiveCell = "y" Or ActiveCell = "NUMBER OF TURNS" Or ActiveCell = "MAX TORQUE" Or ActiveCell = "DEPTH (INCHES)" Or ActiveCell = "VALVE SIZE" Then
Columns(ActiveCell.Column).Select
Selection.NumberFormat = "0.0000000"

'date format ?
ElseIf ActiveCell = "ACTUALF" Or ActiveCell = "INITIATED" Then
Columns(ActiveCell.Column).Select
Selection.NumberFormat = #3/24/2014#

End If

ActiveCell.Offset(0, 1).Select
Next c
End Sub
The problem I am experiencing is when the program reaches the while loop. The conditions And (ActiveCell.Column) < e and (ActiveCell.Column) >= e Are mis-triggering it is as if the conditions is not evaluated at all or (ActiveCell.Column) >= e is all ways true which it is not).

Originally I wrote the code from the while loop down. The code as shown worked. After I was requested that the code/ability include the capability to copy an entire sheet from another workbook to the workbook where the macro is hosted, the top part of the code was added.

The problem I think arises since the code is set to run on the 2nd sheet the 17th column, Q, is not 17 as assumed. Is there a way to:

1 to alter the syntax of (ActiveCell.Column) < e So it knows I am trying to refer to 17th column on the second/last/active sheet?

2 Or make it so the value of e always refers to 17th column on the current sheet?

thanks
lconner