Looks like the attachment is missing?
Posts by Luke M
-
-
-
Would need to use an event macro. You can right-click on the sheet tab, view code, and paste this in. Modify as needed to match your situation.
Code
Display MorePrivate Sub Worksheet_Change(ByVal Target As Range) Dim rngTrigger As Range 'What cell are we watching? Set rngTrigger = Range("A2") 'Did user change it? If Intersect(Target, rngTrigger) Is Nothing Then Exit Sub Application.ScreenUpdating = False Application.EnableEvents = False Select Case UCase(rngTrigger.Value) 'What are the 8 names, al in upper case? Case "ADAM", "BOB", "CHARLIE", "DAN", "EVAN", "FRANK", "SUE", "JOE" Call MyMacro Range("E9").Value = "Success!" Case Else 'Do nothing? End Select Application.EnableEvents = True Application.ScreenUpdating = True End Sub
-
Welcome to the forum!: This may be tough to enforce, as you should consider possibility of the decimals being 0. I.e., to a computer, the numbers 12.3 and 12.30 are the same, but I'm not sure if the first would meet your criteria. Perhaps we should think about it the other way. If user doesn't input enough decimals, you can assume the trailing decimals would be 0. If they enter too many, is that a problem?
Overall, why are we testing for this?
-
Unfortunately, that type of event macro only picks up hyperlinks in cells, not ones assigned to shapes.
If you still want to use shapes/buttons, you'd need to use a specific macro like
CodeSub Test() Dim rngDest As Range Set rngDest = Worksheets("Sheet2").Range("C200") Application.Goto rngDest, True End Sub
Or, if you switch to just regular hyperlinks in cells (perhaps format the cell the "look" like a button), then your code would be:
-
You're very welcome. I'm wondering if maybe you didn't see the 2nd and 3rd line of the formula?
=0.76*SUM(LOOKUP(B2,'Monthly PV'!$B$1:$F$1,INDEX('Monthly PV'!$B$3:$F$50,MATCH(A2,'Monthly PV'!$A$3:$A$50,0),)),
LOOKUP(C2,'Monthly PV'!$G$1:$J$1,INDEX('Monthly PV'!$G$3:$J$50,MATCH(A2,'Monthly PV'!$A$3:$A$50,0),)),
LOOKUP(D2,'Monthly PV'!$G$1:$J$1,INDEX('Monthly PV'!$G$3:$J$50,MATCH(A2,'Monthly PV'!$A$3:$A$50,0),)))The 2nd line is what's getting the corresponding value for C2; it looks in col G:J of the Monthly PV sheet. Similar for 3rd line, it's looking at D2 and fetching value from G:J as well.
-
We can solve half the problem by removing the self-referencing sheet names from the formulas, and just have the cell address. To make your formulas more robust on looking things up from the refrence sheet, you could use the power of lookup formulas to let XL figure out which column and row it needs to be looking at.
In the attached, I first changes all your dates to be real dates, rather than just strings. Then, I setup a lookup range on your Monthly EV sheet. Last, I changed the main formula in col F to use lookup formulas to figure out which column/row to extract data from. All of the year sheets have the exact same formulas, no need to change anything when you copy the sheet. There's even a formula on the worksheet that pulls in the sheet name, so it knows what year you're trying to find.
-
Testing if tags will auto-indent code.
Using CODE tag
Usinng VB tag
[vb]
Sub Test()
Dim x as Long
x = 5
If x < 5 Then
x = 10
End If
End Sub
[/vb]Using vba tag
[vba]
Sub Test()
Dim x as Long
x = 5
If x < 5 Then
x = 10
End If
End Sub
[/vba][VBA]
Sub Test()
Dim x as Long
x = 5
If x < 5 Then
x = 10
End If
End Sub
[/VBA] -
Something like this perhaps?
Code
Display MoreDim MyPath As String Dim DestPath As String Dim MyFile As String Dim MyExt As String Dim wb As Workbook Dim NewFile As String Dim strCheck As String Dim i As Long Dim strTemp As String MyPath = "C:\Users\Owner\Dropbox\Accounts Miqlat\" DestPath = "C:\Users\Owner\Dropbox\Accounts Miqlat\Imported\" 'Destination to move completed file too MyExt = "*.xlsx" MyFile = Dir(MyPath & MyExt) 'Check if file exists already strTemp = MyFile strCheck = Dir(DestPath & MyFile) Do Until strCheck = "" i = i + 1 strTemp = Replace(MyFile, Mid(MyExt, 2), "(" & i & ")" & Mid(MyExt, 2)) strCheck = Dir(DestPath & strTemp) Loop FileCopy MyPath & MyFile, DestPath & strTemp 'copy file to new location
-
Can you elaborate on what the formula is intended to do? It's simulatenously checking 3 cells for a specific string, but there's nothing there currently that handles the array output. If the overall goal is to get difference of D3 - C3, then you should be able to just change the cell format of C3:D3 to whatever format you want (e.g. h:mm AM/PM for example) and the formula would still work.
-
-
Try it like this
Code
Display MorePrivate Sub Worksheet_Activate() Dim wSheet As Worksheet, l As Long Application.ScreenUpdating = False Me.Move Before:=Sheets(1) l = 1 With Me .Columns(1).ClearContents .Cells(1, 1) = "INDEX" .Cells(1, 1).Name = "Index" .Cells(1, 1).Font.Bold = 1 End With For Each wSheet In Worksheets If wSheet.Name <> Me.Name Then l = l + 1 With wSheet ' Uncomment for the first time then comment again ' .Rows("1:1").Insert Shift:=xlUp ' .Rows("1:1").Clear .Range("A1").Name = "Start_" & .Index .Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _ SubAddress:="Index", TextToDisplay:="Back to Index" .Range("A1").Font.ColorIndex = xlAutomatic Me.Hyperlinks.Add Anchor:=Me.Cells(l, 1), Address:="", _ SubAddress:="Start_" & .Index, TextToDisplay:=wSheet.Name 'Don't color cell if tab isn't colored If wSheet.Tab.Color Then Me.Cells(l, 1).Interior.Color = wSheet.Tab.Color Else Me.Cells(l, 1).Interior.Color = xlNone End If End With End If Me.Columns(1).AutoFit Next wSheet Application.ScreenUpdating = True End Sub
-
Re: Delete multiple rows with zero or blank
Hello Busted234, and welcome to the forum.
My first idea would be non-macro, but to use a helper column and formulas. In helper column put this formula:
=AND(C2=0, D2=0)Filter this column for TRUE, then delete all visible rows. Remove filter, then delete helper column
If you're still wanting a macro, you could record yourself doing the above and you'll have a pretty good start.
-
Re: Can I increase speed performance on this value copy loop?
So, it looks like you're using some cells as a processing tool, just feeding 50 cells at a time through them. What's the calculation time for this process? Do you have volatile formulas in your workbook that are slowing things down?
I optimized the code a tiny bit, but not enough to see significat change. The 50 cells at a time bit is definitely your choke-point. Options are to speed up worksheet formulas, or process more than 50 at a time I'd guess at this point.Code
Display MoreSub PullValues() Dim vRowCounter As Long Dim vRowStart As Long Dim vRowEnd As Long Dim vRowEndofRange As Long Dim vRowStartofRange As Long Dim vTotalRows As Long Dim wsOp As Worksheet Dim wsTarget As Worksheet Application.ScreenUpdating = False vRowStart = Worksheets("Start Macro").Range("C6").Value vRowEnd = Worksheets("Start Macro").Range("C8").Value Set wsTarget = Worksheets("Target") Set wsOp = Worksheets("Op Facility Augmentation") vRowStartofRange = vRowStart vTotalRows = vRowEnd - vRowStart + 1 With wsTarget For vRowCounter = 1 To vTotalRows Step 50 vRowEndofRange = vRowStartofRange + 49 wsOp.Range("C14").Resize(50, 1).Value = .Range(.Cells(vRowStartofRange, 5), .Cells(vRowEndofRange, 5)).Value wsOp.Range("E14").Resize(50, 1).Value = .Range(.Cells(vRowStartofRange, 7), .Cells(vRowEndofRange, 7)).Value .Range(.Cells(vRowStartofRange, 8), .Cells(vRowEndofRange, 8)).Value = wsOp.Range("F14").Resize(50, 1).Value .Range(.Cells(vRowStartofRange, 9), .Cells(vRowEndofRange, 9)).Value = wsOp.Range("H14").Resize(50, 1).Value vRowStartofRange = vRowStartofRange + 50 Next vRowCounter .Range(.Cells(vRowStart, 10), .Cells(vRowEnd, 10)).Value = wsOp.Range("D5").Value .Range(.Cells(vRowStart, 12), .Cells(vRowEnd, 12)).Value = wsOp.Range("F5").Value .Range(.Cells(vRowStart, 13), .Cells(vRowEnd, 13)).Value = wsOp.Range("C11").Value If wsOp.Range("J6").Value = 2 Then .Range(.Cells(vRowStart, 11), .Cells(vRowEnd, 11)) = "Yes" ElseIf wsOp.Range("J6").Value = 3 Then .Range(.Cells(vRowStart, 11), .Cells(vRowEnd, 11)) = "No" End If .Range("H:H").NumberFormat = "General" End With Application.ScreenUpdating = True End Sub
-
Re: index not returning all values instead #NUM
YOur current formula structure is more if you were returning items for a single cirtieria. Since your's keeps changing, change formula in B4 to this (still an array)
=INDEX(appno,SMALL(IF(acctname=C4,ROW(acctname)),COUNTIF(C$4:C4,C4)))
Then copy down.
Also, might want to change definition of acctname to only be $A$1:$A$3000, rather than all 1 million rows. Would help decrease your calculation load a lot.
-
Re: Closing a specific workbook automatically closes the form
Are there any macros in the DATA_FILE workbook, specifically a workbook_close event that might be getting triggered and messing things up?
-
Re: Splitting activity duration by half an hour intervals
Hi rafuk,
I'm not sure about the boundary conditions (if start/end time is exactly on the half hour) how things should be handled, but I think this is a good start. I also changed the formatting to display duration, rather than time. If statement checks if the time slot is the first or one of the middle slots. If it is, divide the total duration by the number of periods that fit within our range. Otherwise, be blank.
-
Re: Vlookup 1004 error
Taking a guess, are you sure that the Vlookup will always be successful? If the VLookup can't find the search item it'll return an error and crash the code.
-
Re: If two columns don't match, date stamp a 3 column
Kevin,
Glad to hear. Come back any time, we're all students at different levels.
Cheers!
-
Re: If two columns don't match, date stamp a 3 column
Hi Kevin, and welcome to the forum!
I think this will do what you ask.
Code
Display MorePrivate Sub Worksheet_Change(ByVal Target As Range) Dim rngFirst As Range Dim rngSec As Range Dim rngThird As Range Dim myRow As Long Dim c As Range 'Where are the columns of interest? 'Call-out entire columns here Set rngFirst = Range("A:A") Set rngSec = Range("B:B") Set rngThird = Range("C:C") Application.EnableEvents = False Application.ScreenUpdating = False 'Loop over target, in case multiple cells changed For Each c In Target.Cells 'Did user change one of our cells? If Intersect(c, rngFirst) Is Nothing And Intersect(c, rngSec) Is Nothing Then 'Do nothing Else myRow = c.Row 'Compare the values, decide what to do If rngFirst.Cells(myRow).Value <> rngSec.Cells(myRow).Value Then rngThird.Cells(myRow).Value = Now Else rngThird.Cells(myRow).ClearContents End If End If Next c Application.ScreenUpdating = True Application.EnableEvents = True End Sub