Advanced Excel Tricks and Tips
Simple macro code for collate data
Advanced Macro for data collate
Merge multiple sheets into one
Select multiple column in VBA mode (Macro)
31 Important Excel Functions
FREQUENCY |
INDEX & MATCH |
LOOKUP |
VLOOKUP |
HLOOKUP |
SUMIF |
SUMIFS |
COUNTIF |
COUNTIFS |
COUNTA & COUNTBLANK |
AVERAGEIF & AVERAGE IFS |
SUBTOTAL |
SUMPRODUCT |
IF FORMULA |
NESTED IF |
LEFT, MID, RIGHT & FIND |
REPEAT |
SUBSTITUTE |
PMT,IPMT, PPMT, PV, FV |
|
31 important excel formulas with their practical example.
15 Excel Combo
=TRIM(CLEAN(PROPER(E2)))
=IF(P2>80,"Execlent",IF(P2>=80,"Good",IF(P2<80,"Poor")))
=IF(P15>0,MAX(O14:O14)+1,"")
=IF(AND(C5>=18,D5>=18,E5>=18,F5>=18,G5>=18),"Pass","Fail")
=IF(M6>0,L5+1,"")
=IF(H5<=24,"Poor",IF(H5<=54,"Need
Improvement",IF(H5<=74,"Good",IF(H5<=100,"Excellent"))))
=IF(H5<=24,"D",IF(H5<=54,"C",IF(H5<=74,"B",IF(H5<=100,"A"))))
=COUNTIF(C5:G5,">=30")
=IF(COUNTIF(D5:H5,">=30")=5,"Pass","Fail")
=IFERROR(K14,"Invalid
number")
=FIND("@",J2,1)
=RIGHT(J2,LEN(J2)-K2)
=LEFT(J2,L2-1)
=TEXT(WEEKDAY(B2,1),"DDDD")
***********************************************************************************
Vlookup on Duplicate values
Unique IDs using COUNTIF
Let’s say we want to lookup the second score for Student ID = 2021-A in this dataset:
First, we will create unique IDs in column B by joining the original student ID (column C) with a COUNTIF Function:
=C3&"-"&COUNTIF($C$3:C3,C3)
The COUNTIF Function counts the number of each Student ID. By locking one cell reference in the COUNTIF Function, but not the other, we identify each instance of a duplicate Student ID with a unique number:
=COUNTIF($C$3:C3,C3)
Then we simply use the & operate to concatenate everything together as in the previous formula.
Vlookup Cheat Sheet
Randomization
Random Number 100 - 500 : =RANDBETWEEN(100,500)
Random Number Decimal 1 - 50 : =RANDBETWEEN(1*10,50*10)/10
Random Dates 1-Jul-2021 to 31-Jul-2021 : =RANDBETWEEN(DATEVALUE("1-July-2021"),DATEVALUE("31-July-2021"))
Random time between 9:00 AM to 6:30 PM : =TIME(9,0,0)+RAND()*TIME(18,30,0)-TIME(9,0,0) Random Alphabet between A to Z : =CHAR(RANDBETWEEN(CODE("A"),CODE("Z")))
Random text string/ password : =RANDBETWEEN(0,9)&CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(97,122))&CHAR(RANDBETWEEN(33,47))
Random Names : =CHOOSE(RANDBETWEEN(1,9),$A$26,$A$27,$A$28,$A$29,$A$30,$A$31,$A$32,$A$33,$A$34)
VBA for Macro(Professional)
Brouws File
Private Sub CommandButton1_Click() Dim files Dim FildialogueOpen As Office.FileDialog Set FildialogueOpen = Application.FileDialog(msoFileDialogOpen) FildialogueOpen.Show files = FildialogueOpen.SelectedItems(1) If files = "" Then MsgBox "File not selected!" Exit Sub Else Workbooks.Open (files) End If End Sub
Code for Userform
Just copy this code and paste in your
Dashboard user form, You can design and follow the step as per the video.
Dim LblEvent(11) As New Class1
Private Sub UserForm_Initialize()
Application.Visible = False
Dim Pivt As PivotTable
Dim Slicer As SlicerCache
'Refresh Pivot Table
For Each Pivt In Sheet2.PivotTables
Pivt.PivotCache.Refresh
Next
'Reset Slicer
For Each Slicer In ActiveWorkbook.SlicerCaches
Slicer.ClearManualFilter
Next
For ChNo = 1 To 3
FilePath =
Environ$("Temp") & "\Chart" & ChNo &
".jpg"
Sheet2.Activate
Sheet2.Shapes("Chart" & ChNo).Select
ActiveChart.Export FilePath
Me("Img" &
ChNo).Picture = LoadPicture(FilePath)
Kill FilePath
Next ChNo
Me.TotSale = Format(Sheet2.Range("B1"), "STandard")
'Add Event
For AddEvent = 0 To 11
Set LblEvent(AddEvent).LblBtn
= Me("Label" & AddEvent + 1)
Next AddEvent
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Application.Visible = True
End Sub
Insert a Class Module and paste the
following code
Public WithEvents LblBtn As MSForms.Label
Private Sub LblBtn_Click()
Dim Slicer As SlicerCache
BtnNo = Replace(LblBtn.Name, "Label", "")
If UserForm1.Controls("Image" & BtnNo).Visible = True Then
UserForm1.Controls("ImageSec" & BtnNo).Visible = True
UserForm1.Controls("Image" & BtnNo).Visible = False
Else
UserForm1.Controls("ImageSec" & BtnNo).Visible = False
UserForm1.Controls("Image" & BtnNo).Visible = True
End If
For Each Slicer In ActiveWorkbook.SlicerCaches
If
UserForm1.Controls("ImageSec" & BtnNo).Visible = True Then
Slicer.SlicerItems(Left(LblBtn.Caption, 3)).Selected = False
Else
Slicer.SlicerItems(Left(LblBtn.Caption, 3)).Selected = True
End If
Next
UserForm1.TotSale = Format(Sheet2.Range("B1"),
"STandard")
For ChNo = 1 To 3
FilePath =
Environ$("Temp") & "\Chart" & ChNo &
".jpg"
Sheet2.Activate
Sheet2.Shapes("Chart" & ChNo).Select
ActiveChart.Export FilePath
UserForm1.Controls("Img" & ChNo).Picture =
LoadPicture(FilePath)
Kill FilePath
Next ChNo
End Sub
***********************************************************************************
Private Sub Workbook_Open()
UserForm1.WindowState = xlMaximized
UserForm1.Show
End Sub
Private Sub UserForm_Initialize()
Dim Pivt As PivotTable
'Refresh Pivot Table
For Each Pivt In Sheet2.PivotTables
Pivt.PivotCache.Refresh
Next
For ChNo = 1 To 2
FilePath = VBA.Environ$("Temp") & "\Chart" & ChNo & ".jpg"
Sheet2.Activate
Sheet2.Shapes("Chart" & ChNo).Select
ActiveChart.Export FilePath
Me("Img" & ChNo).Picture = LoadPicture(FilePath)
Kill FilePath
Next ChNo
End Sub
Private Sub ComboBox1_Change()
' Determine the selected chart from ComboBox1 or ComboBox2
If ComboBox1.Text = "Option 1" Then
For ChNo = 1 To 2
FilePath = VBA.Environ$("Temp") & "\Chart" & ChNo & ".jpg"
Sheet2.Activate
Sheet2.Shapes("Chart" & ChNo).Select
ActiveChart.Export FilePath
Me("Img" & ChNo).Picture = LoadPicture(FilePath)
Kill FilePath
Next ChNo
ElseIf ComboBox1.Text = "Option 2" Then
For ChNo = 1 To 2
FilePath = VBA.Environ$("Temp") & "\Chart" & ChNo + 1 & ".jpg"
Sheet2.Activate
Sheet2.Shapes("Chart" & ChNo + 1).Select
ActiveChart.Export FilePath
Me("Img" & ChNo + 1).Picture = LoadPicture(FilePath)
Kill FilePath
Next ChNo
Else
Exit Sub ' No chart selected
End If
End Sub
Private Sub UserForm_Initialize()
' Populate ComboBox with options
ComboBox1.List = Array("Option 1", "Option 2")
'ComboBox2.List = Array("Option 3", "Option 4")
Dim Pivt As PivotTable
'Refresh Pivot Table
For Each Pivt In Sheet2.PivotTables
Pivt.PivotCache.Refresh
Next
End Sub
No comments:
Post a Comment