Re: Special Average Formula
Already found this, looks a bit better (but thanks for your help!!):
=SUMPRODUCT(--(MOD(ROW(B3:B23),5)=3),--(MOD(ROW(B4:B24),5)=4),--(B3:B23<>""),B4:B24)/SUMPRODUCT(--(MOD(ROW(B3:B23),5)=3),--(B3:B23<>""))
Re: Special Average Formula
Already found this, looks a bit better (but thanks for your help!!):
=SUMPRODUCT(--(MOD(ROW(B3:B23),5)=3),--(MOD(ROW(B4:B24),5)=4),--(B3:B23<>""),B4:B24)/SUMPRODUCT(--(MOD(ROW(B3:B23),5)=3),--(B3:B23<>""))
I have 5 products and every product has it's own correction percentage. Sometimes I fill in this percentage only for one, two, three, four or five products. The correction percentage is always filled in by default at 100%.
Is there a way to calculate the average of these percentages?
For every product I have to fill in the cell with volume, so if there is no volume filled in then also the percentage doesn't count.
I.E. I use in this case only 1 product, and set the percentage to 75%, and there are no other products (so the other 4 products are by default on 100%). I want to see on the total sheet an average of 75%. And not 475% divided by 5. Can anyone help me?
Please see also the example on:
Re: Closing workbook with VBA without SAVING
This is great, but when I click on YES. the original template still remains open.
I want it to close the original template file after copying to the new workbook.
Re: Closing workbook with VBA without SAVING
Thanks for your help, but unfortunately I'm still getting this message box popup twice. So even when I click on NO, I get once again the same messagebox. I have to click once again on NO. The same is for the YES button.
I'm trying to close a workbook without saving it. But everytime I get the message box popupped twice. Can anyone help me?
These are the codes that I use:
Private Sub Workbook_BeforeClose _(Cancel As Boolean)
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String
QuestionToMessageBox = "Are you sure you want to CLOSE and SAVE the template?"
YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "Go back to template")
If YesOrNoAnswerToMessageBox = vbNo Then
Range("A1").Select
Workbooks("Template.XLSM").Close Savechanges:=False
Else
Call Copy_ActiveSheet
Workbooks("Template.XLSM").Close Savechanges:=False
End If
End Sub
Display More
And the Code for: Call Copy_ActiveSheet
Sub Copy_ActiveSheet(Optional x As Boolean)Application.ScreenUpdating = False
'Working in Excel 2000-2010
Dim fname As Variant
Dim NewWb As Workbook
Dim FileFormatValue As Long
'Check the Excel version
If Val(Application.Version) < 9 Then Exit Sub
If Val(Application.Version) < 12 Then
'Only choice in the "Save as type" dropdown is Excel files(xls)
'because the Excel version is 2000-2003
fname = Application.GetSaveAsFilename(InitialFileName:="", _
filefilter:="Excel Files (*.xls), *.xls", _
Title:="This example copies the ActiveSheet to a new workbook")
If fname <> False Then
'Copy the ActiveSheet to new workbook
Dim myArray() As Variant
Dim i As Integer
Dim j As Integer
j = 0
For i = 1 To Sheets.Count
If Sheets(i).Visible = True Then
ReDim Preserve myArray(j)
myArray(j) = i
j = j + 1
End If
Next i
Sheets(myArray).Select
Sheets(myArray).COPY
ActiveSheet.Unprotect Password:="testing"
ActiveSheet.Shapes.SelectAll
Selection.Delete
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
ActiveSheet.EnableOutlining = True
Call Unhide_K_P
If ActiveSheet.Index = Worksheets.Count Then
Worksheets(1).Select
Else
ActiveSheet.Next.Select
End If
ActiveSheet.Unprotect Password:="testing"
ActiveSheet.Shapes.SelectAll
Selection.Delete
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
Call Unhide_K_P
If ActiveSheet.Index = Worksheets.Count Then
Worksheets(1).Select
Else
ActiveSheet.Next.Select
End If
ActiveSheet.Unprotect Password:="testing"
ActiveSheet.Shapes.SelectAll
Selection.Delete
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
ActiveSheet.EnableOutlining = True
Call Unhide_K_P
Set NewWb = ActiveWorkbook
'We use the 2000-2003 format xlWorkbookNormal here to save as xls
NewWb.SaveAs fname, FileFormat:=-4143, CreateBackup:=False
Set NewWb = Nothing
End If
Else
'Give the user the choice to save in 2000-2003 format or in one of the
'new formats. Use the "Save as type" dropdown to make a choice,Default =
'Excel Macro Enabled Workbook. You can add or remove formats to/from the list
fname = Application.GetSaveAsFilename(InitialFileName:="", filefilter:= _
" Excel Macro Free Workbook (*.xlsx), *.xlsx," & _
" Excel Macro Enabled Workbook (*.xlsm), *.xlsm," & _
" Excel 2000-2003 Workbook (*.xls), *.xls," & _
" Excel Binary Workbook (*.xlsb), *.xlsb", _
FilterIndex:=2, Title:="This example copies the ActiveSheet to a new workbook")
'Find the correct FileFormat that match the choice in the "Save as type" list
If fname <> False Then
Select Case LCase(Right(fname, Len(fname) - InStrRev(fname, ".", , 1)))
Case "xls": FileFormatValue = 56
Case "xlsx": FileFormatValue = 51
Case "xlsm": FileFormatValue = 52
Case "xlsb": FileFormatValue = 50
Case Else: FileFormatValue = 0
End Select
'Now we can create/Save the file with the xlFileFormat parameter
'value that match the file extension
If FileFormatValue = 0 Then
MsgBox "Sorry, unknown file extension"
Else
'Copies the ActiveSheet to new workbook
j = 0
For i = 1 To Sheets.Count
If Sheets(i).Visible = True Then
ReDim Preserve myArray(j)
myArray(j) = i
j = j + 1
End If
Next i
Sheets(myArray).Select
Sheets(myArray).COPY
ActiveSheet.Unprotect Password:="testing"
ActiveSheet.Shapes.SelectAll
Selection.Delete
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
ActiveSheet.EnableOutlining = True
Call Unhide_K_P
On Error Resume Next
Sheets(ActiveSheet.Index + 1).Activate
If Err.Number <> 0 Then Sheets(1).Activate
ActiveSheet.Unprotect Password:="testing"
ActiveSheet.Shapes.SelectAll
Selection.Delete
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
Call Unhide_K_P
On Error Resume Next
Sheets(ActiveSheet.Index + 1).Activate
If Err.Number <> 0 Then Sheets(1).Activate
ActiveSheet.Unprotect Password:="testing"
ActiveSheet.Shapes.SelectAll
Selection.Delete
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
ActiveSheet.EnableOutlining = True
Call Unhide_K_P
Set NewWb = ActiveWorkbook
'Save the file in the format you choose in the "Save as type" dropdown
NewWb.SaveAs fname, FileFormat:= _
FileFormatValue, CreateBackup:=False
Set NewWb = Nothing
End If
End If
End If
Application.ScreenUpdating = True
End Sub
Display More
Re: Save sheet(s) to new document and save & close document to desktop
Already found something like this:
Sub Macro3()
'
' Macro3 Macro
'
'
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Visible = xlSheetVisible Then
ws.Select
ActiveSheet.Select
ActiveSheet.COPY
ActiveSheet.Protect Password:="testing", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, UserInterfaceOnly:=True
ActiveSheet.EnableOutlining = True
End If
Next ws
End Sub
Display More
And this works, but only if there is 1 sheet active. When there is more than one sheet active I get an error at this line:
And one more thing: After copying the 1 sheet (at this moment) and I click on the SAVE button it give me this message:
https://www.box.com/files/0/f/0/1/f_4105595897
I just want to save it as a default Excel file, with no macro's/vba's.
Re: Save sheet(s) to new document and save & close document to desktop
No one any idea??? Please help.sdfsd
Hi,
I made a Excel file, with Userform and many macro's. After the user has filled in the required fields, I don't want him to be able to save and overwrite the file. I just want to give him the option, upon clicking close (the red X button), to save the active sheets to a new document and save that file to the users desktop.
Anyone an ideao how I can do that with VBA?
So clicking CLOSE ==> Message: Do you want to save the file? ===> YES or NO???
If YES ==> Copy and paste the active sheets to new document and save it to the desktop.
If NO ==> Close document without saving.
And SAVE button should be disabled, so that the user cannot overwrite original file.
Also posted on: http://www.mrexcel.com/forum/e…ications.html#post3323381
Re: TextBox with only numeric values
Once again: Thanks a lot!!!!! This is perfect.
Re: TextBox with only numeric values
I'm really sorry, but one last question, then I won't bother you anymore.
Is there also a possibility to add the Tab back function, (so SHIFT + TAB), to go to the previous field/textbox?
Re: TextBox with only numeric values
This works great!!! I'm really thankfull.
Do you know how I can restrict the user to enter [email protected]#$^&*() ?????
Because these signs are still possible to enter in the textbox
Re: TextBox with only numeric values
Wowwww, this works great. One little question: Since I entered your code, I cannot go to the next field/textbox with the Tab key. And it's only in this textbox, all the other textboxes still work with the Tab key. Any idea how to solve this?
And also: What does Case 8, 13, 46, 48 To 57, 96 To 105, 110 mean?
Hi,
I want to let the user only fill in an numeric value, and let the numeric value show as value + %. So if he/she enter 10, then it should show 10%. And if he/she enters 10%, it should pop up a message to only enter numeric value. And after entering the numeric value of 10, he/she should see 10%.
Right now I found something like this (see below), but the issue with is that the user still can enter non numeric values, and also i.e. 10%. After entering 10%, he/she sees 10%% (so double %). I want to prevent this. Anyone an idea how?
Hi,
I have a userform with several comboboxes, and I when I select an item from combobox1, I have made it to filter (with RowSource within VBA) and only show the possible solution in combobox2. But now I want to add combobox3 (also with RowSource), with the ability to only show combobox3 when in combobox2 "ECY" is selected. And if combobox3 is filled, then the user should be able to also fill in combobox 4 (filtering again on possible values depending on combobox3). So if the user hasn't picked in combobox2 "ECY", then he should be able to fill combobox3 and combobox4.
Can anyone help me please???
Please see below the code that I have for filtering between combobox1 (with RowSouce)and combobox2:
Private Sub ComboBox1_Change()Dim strRange As String
If ComboBox1.ListIndex > -1 Then
strRange = ComboBox1
Label2.Caption = strRange
strRange = Replace(strRange, " ", "_")
With ComboBox2
.RowSource = vbNullString
.RowSource = strRange
.ListIndex = 0
End With
Else
Label2.Caption = "Project subtype:"
End If
End Sub
Display More
Hi,
I want to copy some selected rows to another sheet.
I.E. Starting with cell AP1 and going down with CTRL+SHIFT+down arrow until he finds the next "X". And then select all these rows, and copy to sheet2.
What I have right now is (But it's not working):
QuoteDisplay More
Range("AP1").Select
Range(Selection, Selection.End(xlDown)).Select
Rows(ActiveCell.Row).Select
Selection.COPY
Sheets2.Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Re: restricting textbox to fill only negative values
I used this code and worked for me, thanks for your help guys:
Re: restricting textbox to fill only negative values
This is almost what I'm looking for. But the only issue is when I have an empty textbox, I'm still getting a message. Is it possible to NOT getting a message on an empty textbox, but only when data is filled in?
Hi,
I'm using DatePicker (DTPicker) in my userform, and I want the user to fill in a start-date and end-date, but when I add the DatePicker, it automatically sets the date to today. I want it to be clear, and to let the user fill it in. How can I do that?
Hi,
I want to restrict a textbox to only let the user fill negative values. So first of all he/she shouldn't be able to fill in a text, and only values. And if a value is filled in, then it should be a negative value (automatically).
Hi,
I want to convert a date from a textbox. When I enter a date in textbox it convert to US date.
I.E. 1-11-2012 and it makes 11-1-2012 upon unloading the userform. But I want to have 01-11-2012 (so 1st November 2012)
What do I have to add/change in VBA to get 01-11-2012. And is there also a possibility to force the user to enter in MM-DD-YYYY format? And if not entered correctly, there should popup a messagebox.
Thanks in advance!!!