Re: Retrieve Current Controls Event
Maria
What would you use this for?
What if the control has multiple events associated with it?
Re: Retrieve Current Controls Event
Maria
What would you use this for?
What if the control has multiple events associated with it?
Re: Nested Loops Quit after one successful round
The problem with activating workbooks/sheets isn't to do with memory drain, activating just isn't needed and slows things down.
It also makes it hard to debug things as it can get kind of confusing as to what's actually active when.
Anyway, here's your code without any activating.
Option Explicit
Global UtilData As String
Global FinanceData As String
Global ULastCol As Long
'________________________________
Sub Months()
Dim wbUtil As Workbook
Dim wbFinance As Workbook
Dim FLastCol As Long
Dim FLastRow As Long
Dim UCAC() As String
Dim ULastRow As Long
Dim FFindCell As Range
Dim SrchCell As String
Dim CurrentUCAC As String
Dim iReply As VbMsgBoxResult
Dim I As Long
Dim X As Long
Dim Y As Long
Dim W As Long
'**** Some set-up code - I am not having problems with this code, just including it for reference****
'Workbooks(UtilData) is the workbook with the updated format.
'Workbooks(FinanceData) is the workbook with the original data in its original format. This version works great for our finance folk, but not so much for my analyses.
Set wbUtil = ActiveWorkbook ' UtilData = ActiveWorkbook.Name
iReply = MsgBox("Please open the new utility data file. The Macro will copy / paste the new data into the existing table.", vbOKCancel, Title:="Launch Transfer")
If iReply = vbOK Then
Application.FindFile
Set wbFinance = ActiveWorkbook ' Data = ActiveWorkbook.Name
End If
'Workbooks(UtilData).Sheets("Utility Data").Activate
ULastCol = wbUtil.Sheets("Utility Data").Cells(1, Columns.Count).End(xlToLeft).Column
With wbFinance.ActiveSheet 'Workbooks(FinanceData).Activate
FLastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
FLastRow = .Cells(Rows.Count, 7).End(xlUp).Row
'Use "City Acct Code" as anchors to copy / paste data. There will be a separate row for each month.
ReDim UCAC(2 To FLastRow)
For I = 2 To FLastRow
UCAC(I) = .Cells(I, 3)
Next I
End With
'***End Set-up Code*********
ULastRow = wbUtil.Sheets("Utility Data").Cells(Rows.Count, 3).End(xlUp).Row
With wbFinance.ActiveSheet
SrchCell = "July kwh"
For X = 2 To FLastRow
CurrentUCAC = UCAC(X) 'If this looks funky, that's because I use the String in another bank of code not shown here. However, I'm not convinced this is the problem bc the loop never makes it back to this variable.
If .Cells(X, 3) = CurrentUCAC Then
For Y = 7 To 19 'This is the loop that is failing.
Set FFindCell = .Cells(1, Y).Find(SrchCell, LookIn:=xlValues)
If Not FFindCell Is Nothing Then
.Cells(X, Y).Copy
For W = 3 To ULastRow
If wbUtil.Sheets("Utility Data").Cells(W, 3) = CurrentUCAC And wbUtil.Sheets("Utility Data").Cells(W, 9) = SrchCell Then
wbUtil.Sheets("Utility Data").Cells(W, 11).PasteSpecial (xlPasteValues)
SrchCell = FFindCell.Offset(0, 1)
End If
Next W 'Everything works great until this loop has one successful completion of code (i.e. it successfully copy/pastes values). Then the Sub just ends, and does not finish 'y = 7 to 19'
End If
Next Y 'This is the loop that is failing. I want 'y' to run through columns 7 to 19, currently it's quitting at 8. Column 8 is the first relevant column to the copy/paste method.
End If 'This loop is not completed either. 'x' should loop to row 900-ish. If I create breakpoints and run the program slowly, it runs perfect! But it I let it run on its own, at full speed, it does one successful loop and ends.
Next X
End With
End Sub
Display More
Re: Stop Auto_open macro running in other open workbooks
The problem is with Application.OnTime not AutoOpen, you need to cancel the OnTime when you close workbook A or Excel/VBA will keep on trying to run it and to do that it needs to open workbook B.
Re: I keep getting #Name? for the answer to the cell.
Yes, otherwise Excel will think you are trying to refer to a named range and you'll get errors.
Re: I keep getting #Name? for the answer to the cell.
ADMIN, MAINT ADMIN etc should be in quotes otherwise Excel will treat them as named ranges.
=IF('MANAGER ONLY'!$D$3:$D$200="ADMIN",'MANAGER ONLY'!A$3:A$200,"")
Re: Receiving error codes with using user form to rearrange and remove columns
What exactly are you trying to do?
Are you just trying to copy a selected no of columns, and all the data in those columns, to a new worksheet?
Or do you actually want to filter data?
If it's the latter where would the criteria for the filter come from?
Re: Receiving error codes with using user form to rearrange and remove columns
Why are you using advanced filter if you want to copy entire columns?
Re: Receiving error codes with using user form to rearrange and remove columns
Don't get any errors when doing that I'm afraid.
Re: Receiving error codes with using user form to rearrange and remove columns
How can we replicate the problem?
Re: Link to upload a document
What/where do you actually want to 'attach'/'upload' the document to?
Re: Date formating when saving to excel sheet
Don't use Format if you want real dates, use CDate or DateValue but check there's a date in the textbox before you do anything.
If Me.TextBox8.Value <> "" And IsDate(Me.TextBox8.Value Then
ws.Cells(iRow, 4).Value = Format(Me.TextBox8.Value, "DD/MM/YY")
End If
PS You should consider using a listbox.
Re: VBA Compile Error: Syntax Error, From Very Long Formula
What, in words, is the formula supposed to count/sum/do?
Re: Export workbook
I don't mean to be ignorant, but what's an '.ebm' file?
Can Excel save with that file type?
Does it require an add-in?
Re: Frame a subset of a group of option buttons
Why do you want Ascending and Descending in a separate frame?
Isn't that going to be a bit confusing?
Re: Textbox doesn't populate sheet with new value (AfterUpdate)
Format the cell(s) you are putting the value into as Text.
Re: VBA Overflow Error
Where does Pc get a value?
Also, where in the code do you actually get th error?
Re: Number DIMs automatically
2 Worksheets(Sheet1) will not work unless their is a variable named Sheet1, if you are trying to refer to a worksheet with the codename Sheet1 then you would just use Sheet1, you don't need the Worksheets part.
4 That still doesn't quite explain why individual cells. You could have a column named CLOSED and you could refer to and treat each of the cells in that column individually.
So you would still have your range names but you would have a lot less of them to deal with.