Re: Error 91 When Closing
atjensen11 you need to post the code here, dont forget if you do you need to highlight all your code and then click the # icon to wrap code tags around it.
regards,
Simon
Re: Error 91 When Closing
atjensen11 you need to post the code here, dont forget if you do you need to highlight all your code and then click the # icon to wrap code tags around it.
regards,
Simon
Re: Update Cell Value
Findeep, you don't have to use a checkbox you could use Y or N or Yes or No,
In column A you have your dates, in column B You Could just enter Y for that date to appear on another sheet, the way you could do this is like this:- paste this where you would like the date to appear on the other sheet, lets say in A1
then copy it down for as many cells as you would have dates for.
The formula reads like this If Sheet1 cell B1 has the value Y then return the value of Sheet1 cell A1 If no Y is present return a blank, it does not matter if you use a capital Y or lower case y use on the sheet.
Hope this helps,
Regards,
Simon
Re: Clear Contents And Change Colour Index Of Cells
Right!, here we go............you need to format all your cells where numbers would appear i.e 00002 (including the ref No. cells) as text this way when the search takes place it will actually look for all of the exact number!, I have added some code in named macro 2 as shown below, i have also made a note in your workbook of what you need to do.
Regards,
Simon
Sub Macro2()
Dim T1
T1 = Sheets("Booking Page").Range("I3")
Application.ReplaceFormat.Interior.ColorIndex = xlNone
Cells.Replace What:=T1, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=True
Application.ReplaceFormat.Interior.ColorIndex = xlNone
Cells.Replace What:=T1, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
Display More
Re: Open Files, Copy Paste To Master Workbook
Hi i modified the code, ran it and it worked perfect every time!
Sub RunCodeOnAllXLSFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbMaster As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbMaster = ThisWorkbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\My Documents\Excel Test"
.FileType = msoFileTypeExcelWorkbooks
'.Filename = "Book*.xls"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Sheets("Sheet1").Select
Range("C4").Select
Selection.Copy
wbMaster.Activate
Workbooks("Wbworkbook").ActiveSheet.Range("B65536").End(xlUp)(2).PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Display More
Regards,
Simon
Re: Open Files, Copy Paste To Master Workbook
Can you post your workbook?, if you post code next time code you highlight your code and then click the # this will wrap code tags around your code and make it much easier to read.
Regards,
Simon
Re: Hiding Rows Based On Values In Other Rows
Hi Clange2 try posting what you have so far i.e your workbook or code you have!
Regards,
Simon
Re: Trigger Filter With Cell Change
FreeBrownies, i think you may need to replace this line
so your code looks something like
Dim rng As Range
Set rng = Range("A11")
If Not Intersect(Target, rng) Is Nothing Then
With Sheet1
.AutoFilterMode = False
.Range("A14").AutoFilter
.Range("A14").AutoFilter Field:=1, Criteria1:="<={the number the user input}", _Operator:=xlAnd, Criteria2:="="
End With
Else:.AutoFilterMode = False
End If
End Sub
Display More
again im not entirely sure here but its my best guess!
Regards,
Simon
Re: ComboBox Change Not Firing Worksheet Change Event
I'm not entirely sure on this but to get a Worksheet Change Event don't we have to "Activate" or "Select" a cell on that sheet?
Regards,
Simon
Re: Copy Event Code To Other Workbooks
Glad you got sorted and thanks for posting the feedback!
Regards,
Simon
Re: Event Code Firing More Than Once
Thanks Dave, and apologies!
Regards,
Simon
Dave, thanks i try with what limited knowledge i have, if you dont mind take a look at the code below, i read your article and added the appropriate line, the code works fine except the msgbox has to be ok'd twice before it exits sub any ideas why?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Dim MyCell
Set rng = Range("A2:A100")
If Not Intersect(Target, rng) Is Nothing Then
With rng
For Each MyCell In rng
If MyCell = "" Then
MyCell.Select
MsgBox "Please use this next blank cell"
Exit Sub
End If
Next
End With
End If
End Sub
Display More
Regards,
Simon
Re: Stop Blanks in Entry Range
LOL! Dave my code only works to a fashion as im no expert, the event is triggered no matter what cell you click, i just didnt know how to only get it to work in the specified range like column A.
Regards,
Simon
Re: Combo Box Firing A Worksheet Change Event
All i can imagine is that if you get a criteria match in the combobox then select a cell like:
then of course you will have code in the worksheet change event for that sheet.
Regards,
Simon
Re: Open Files, Copy And Paste Into Master Workbook
I may not have got this right (i'm sure someone will tell you if i havent) but i have added a couple of lines in the code below:
This one
and
and
Sub RunCodeOnAllXLSFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbMaster As Workbook
Dim rng
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set rng = Sheets("Sheet1").Range("B65536").End(xlUp)(2) ''''assuming your pasting to sheet1
Set wbMaster = ThisWorkbook
With Application.FileSearch
.NewSearch
.LookIn = "S:\Common_Resources\PLs\2006\2006_06\Branch"
.FileType = msoFileTypeExcelWorkbooks
'.Filename = "Book*.xls"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Filename = ActiveCell.Value
sfilename = Filename
Workbooks.Open Filename:= _
(spath & sfilename)
Sheets("Sheet1").Select
Range("C4").Select
Selection.Copy
Windows("Branch Data.xls").Activate
rng.Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
ActiveCell.Offset(0, -1).Range("A1").Select
Windows(sfilename).Activate
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Display More
Like i said not entirely sure im right but give it a go!
Regards,
Simon
Re: Trigger Filter With Cell Change
Check out this thread, http://www.ozgrid.com/forum/showthread.php?t=59414 it sounds like you want conditional formatting really, where if say cell B6 = 3 then show priorities 0,1,2,3 etc, you should be able to modify and work some code around the examples here and the link that Dave Hawley has provided.
Regards,
Simon
Re: Copy Event Code To Other Workbooks
The problem looks to be (although im not sure because i didnt put this together!) that you are opening a workbook
then later on in the code you are selecting the folder where you want to open the workbooks and perform the action
so in other words you are trying to modify the ThisWorkBook module of the workbook that is initiating the procedure
QuoteQuote:
Originally Posted by Johnske
Put all the workbooks that need the new ThisWorkbook procedures into a folder with the book containing the new procedure.
Put this code into a standard module in the book that contains the new procedure and run it (make sure all the other workbooks are closed as I didn't add code to check if thay're open) - this is basically a 'copy and paste' for a VBE module
as you see here Johnske tells you to make sure all the workbooks are closed, you have one open....the one thats doing the work, it shouldnt be in that folder (i dont think!), he also tells you to put this procedure in the workbook that is going to pass the procedure to the other books NOT put it in the same folder!
Clear these few things up and it should work fine.
Regards,
Simon
Re: No Blank Cells
Its something like this but i dont know exactly how to get the action to only work if a cell in rng is selected
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Dim MyCell
Set rng = Range("A2:A100")
With rng
For Each MyCell In rng
If MyCell = "" Then
MyCell.Select
MsgBox "Please use this next blank cell"
Exit Sub
End If
Next
End With
End Sub
Display More
Hopefully this will help you on your way or spark some replies for you,
Regards,
Simon
Re: Triggering Filters With Changes To Cell
Hi i'm not entirely sure what your after, but assuming your priority data is in column A the following code will show an input box where the user can enter a priority figure and then the worksheet will be automatically filtered to your requirements. The code could be triggered by a command button.
Sub FilterIt()
Dim T1, T2
Columns.AutoFilter ''''''''This turns off any filters so if you run the code again you get to see everything first
T1 = InputBox("Enter Priority Number" & Chr(13) & "Either: 0, 1, 2 or 3", "Priority Finder") '''''''''This is the method of allowing the user to enter which priority they would like to see
If T1 = "" Then ''''''these next 3 lines say if you dont select a number or press cancel then nothing happens
Exit Sub
End If
Range("A1").Select '''''selects where to start from
Selection.AutoFilter '''''turns filters on
Selection.AutoFilter Field:=1, Criteria1:=T1 '''''''this tells it which feild to filter and by what
End Sub
Display More
Regards,
Simon
Re: Copy Vba Code To Thisworkbook Object
This code was provided to me by Johnske at VBAExpress for a similar reason.
Quote from JohnskePut all the workbooks that need the new ThisWorkbook procedures into a folder with the book containing the new procedure.
Put this code into a standard module in the book that contains the new procedure and run it (make sure all the other workbooks are closed as I didn't add code to check if thay're open) - this is basically a 'copy and paste' for a VBE module
Option Explicit
Sub ReplaceThisWorkbookProcedures()
Dim N As Long
Dim NewCode As String
'ThisWorkbook is the file containing the new ThisWorkbook procedures
With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
NewCode = .Lines(1, .countoflines)
End With
'open all files you want the new procs in
With Application
.ScreenUpdating = False
.DisplayAlerts = False
With .FileSearch
.LookIn = ThisWorkbook.Path
.Filename = "*.xls"
If .Execute > 0 Then
For N = 1 To .FoundFiles.Count
If .FoundFiles(N) <> ThisWorkbook.FullName Then
Workbooks.Open(.FoundFiles(N)).Activate
'--------Delete old procedures and replace with new--------
With ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
.DeleteLines 1, .countoflines
.InsertLines 1, NewCode
End With
'-----------------------------------------------------------------
ActiveWorkbook.Close savechanges:=True
End If
Next
End If
End With
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Display More
Regards,
Simon