vb code work only in 1 wkbk: lengthy

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
i have the code to give me information from reports. i have asked specific questions before (didn't know if i should post in those, so i apologize if i needed to) about this macro. it's half coded, half recorded.

my problem is that it will only work in one report, and i don't know why. if interested, i can post the code; i won't unless someone asks cause it's so long :( - for a thread that is.

so please inquire if interested :confused:

edit: was going to be lengthy, but decided not to post code. sorry if misleading.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you're specifically referring to a named workbook in your code (like will happen when you record), that could be your problem.

Post away...

Smitty
 
Upvote 0
well here is my code thus far. i know there's a lot of footnotes, but helps me. if anything is not as it should be, please let me know.

thanks.


Code:
Sub GetReport()

    'TURNING OFF UPDATING FOR USER STABILITY
    Application.ScreenUpdating = False
    
    'DELETING BLANK COLUMNS (TRIMMING)
    Columns("A:D").Select
    Range("A65502").Activate
    Selection.Delete Shift:=xlToLeft
    
    'DELETING BLANK ROWS (TRIMMING)
    Rows("1:16").Select
    Range("A16").Activate
    Selection.Delete Shift:=xlUp
    
    'FORMATTING IF/DATE COLUMN
    Columns("G:G").Select
    Selection.NumberFormat = "m/d/yyyy"
    
    'FORMATTING IF/TIME COLUMN
    Columns("H:H").Select
    Selection.NumberFormat = "[$-409]h:mm:ss AM/PM;@"
    
    'TYPING IF/DATE FORMULA
    Range("G2").Formula = "=IF(E2>20,A2,"""")"
    
    'TYPING IF/TIME FORUMLA
    Range("H2").Formula = "=IF(E2>20,B2,"""")"
    
    'SELECTING TWO PREVIOUS FORMULAS AND
    'AUTO FILLING DOWN TWO ROWS
    'NOW CHANGED TO COPY/PASTE (OLD CODE SAVED)
    Range("G2:H2").Copy Range("G3:H4")
    
    'TYPING "FLAG" FORMULA
    Range("I4").Formula = "=IF(COUNT(H2:H6)>3,""Flag"","""")"
    
    'SELECTING ALL THREE FORMULAS -> AUTOFILLING TO END OF DATA
    'NOW CHANGED TO COPY/PASTE (OLD CODE SAVED)
    Range("G4:I4").Copy Range("G5:I65520")
    
    'SELECTING FORMULA COLUMNS
    'ADJUSTING COLUMNS TO AUTOFIT AND
    'COPYING THE COLUMNS DATA
    Columns("G:I").Select
    Range("G65507").Activate
    Columns("G:I").EntireColumn.AutoFit
    Range("I65521").Formula = "=COUNTIF(I2:I65520,""Flag"")"
    Columns("G:I").Select
    Range("G65507").Activate
    Selection.Copy
    
    'PASTING INFO INTO UNUSED SHEET
    Sheets("Sheet1").Select
    Columns("A:C").Select
    'PASTING SPECIAL -> VALUES
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    'PASTING SPECIAL -> FORMATS
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    'PASTING SPECIAL -> COLUMN WIDTHS (FOR PRESENTABILITY)
    Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    
    'STARTING THE AUTOFILTER PROCESS (TO DELETE ALL BLANK ROWS)
    'CAN AUTO FILTER FIELD BY DATE (1), TIME (2) OR FLAG (3)
    Selection.AutoFilter
    Selection.AutoFilter Field:=3, Criteria1:="="
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.EntireRow.Delete
    
    'COPYING RAW DATA - NO EMPTY ROWS - TO NEXT UNUSED SHEET
    Columns("A:C").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Columns("A:C").Select
    'PASTING SPECIAL -> VALUES
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    'PASTING SPECIAL -> FORMATS
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    'PASTING SPECIAL -> COLUMN WIDTHS (FOR PRESENTABILITY)
    Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Sheets("Sheet2").Select
    Application.CutCopyMode = False
    
    'HIDING PERSONAL.XLS BOOK
    Windows("PERSONAL.XLS").Activate
    ActiveWindow.Visible = False
    
    'SETTING NAME FOR FILE
    Dim newFile As String
    newFile = InputBox(Prompt:="What would you like your file name to be?")
        If newFile = Empty Then
        MsgBox Prompt:="You must enter a valid file name."
        Else
        MsgBox Prompt:="Your new report file will be named " & newFile & ".xls"
        End If
    
    'COPYING NEWLY ACQUIRED (& FORMATTED) DATA TO A NEW FILE
    'IN THE SAME FOLDER
    Sheets("Sheet2").Copy
     ChDir _
        "C:\Documents and Settings\Rob\My Documents\EXCEL files off Dell 4100 2Dec01\Data\Kinzua\AIR\reports"
    ActiveWorkbook.SaveAs Filename:= _
        newFile _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
    
    'CLOSING THE ORIGINAL REPORT - DO NOT SAVE ORIGINAL
    '
    'THIS WILL EVENTUALLY NEED TO BE ADJUSTED UNLESS ALL
    'FILE NAMES ARE GOING TO BE THE SAME.  DON'T KNOW THE
    'CODE RIGHT NOW, SO EVERYTHING WILL BE THE SAME, OR THIS
    'WILL BE ADJUSTED EVERY TIME :(
    Windows("Day_Report opacity 2003").Activate
    ActiveWindow.Close False
    
End Sub
 
Upvote 0
Hey Zack,

So what exactly isn't working?

Your code can use some trimming, but it will help to know where/why it's bombing.

I see a few places where an error could occur, but need you to point out the specifics.

Have a great weekend & I hope it's a bit nicer up there this weekend! :LOL:

Smitty
 
Upvote 0
:( - as for the weather.

as for my code, well, i don't get any type of error at all. it runs fine in the one specific file. but anytime i run it in any other file it freezes up and ends up closing out, then wants to send an error report to MS.

i don't know why this is. if you've got any ideas, i think i'm about as far as i can go for now.

i'm leaving it alone until monday cause i wanna o_O my keyboard.

hey, thank you for taking the time to look this one over Smitty. I appreciate the help, lord knows i need it.
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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