Excel Macro & VBA Automation Complete Master Guide in Bangla
Macro Recorder থেকে Professional VBA Coding, Automatic Data Entry, Report Generation, Data Cleaning, Multi-File Consolidation, Dashboard, Chart, PDF Export, Event Automation, Error Handling ও Real Industry Projects—সবকিছু Step-by-Step Practical Example-সহ শিখুন।
1. Excel Macro, VBA ও Automation আসলে কী?
Excel Macro হলো এক বা একাধিক কাজের নির্দেশনা, যা একবার তৈরি করে পরে বারবার চালানো যায়। আপনি একই Report প্রতিদিন Format করেন, Duplicate Data Remove করেন, Formula বসান বা PDF Export করেন—এসব কাজ Macro দিয়ে একটি Click-এ করানো সম্ভব।
VBA-এর পূর্ণরূপ Visual Basic for Applications। এটি Microsoft Office-এর Desktop Automation Language। Macro Recorder আপনার করা কিছু কাজকে VBA Code-এ রেকর্ড করে; আর VBA Editor-এ নিজের Logic, Condition, Loop, Function, Event এবং File Handling লিখে Advanced Automation তৈরি করা যায়।
| পদ্ধতি | কাজ | কখন ব্যবহার করবেন |
|---|---|---|
| Excel Formula | Cell-এর ভিতর Calculation ও Dynamic Result | SUM, IF, XLOOKUP, FILTER, COUNTIFS ইত্যাদি |
| Macro Recorder | আপনার করা Repetitive Click/Format Record | প্রথম Macro শেখা, Simple Formatting |
| VBA Macro | Excel ও Windows Desktop-এর মধ্যে Programmatic Automation | Data Cleaning, Reports, Files, PDF, Buttons, Events |
| Power Query | বিভিন্ন Source থেকে Data Import, Combine ও Transform | একাধিক CSV/Excel File-এর Data Pipeline |
| Office Scripts | TypeScript-ভিত্তিক Excel Workbook Automation | Excel Web/Cloud ও Power Automate Workflow |
| Power Automate | বিভিন্ন App-এর মধ্যে Trigger ও Workflow | Scheduled বা Event-driven Process |
2. কোন Excel-এ VBA Macro কাজ করে? Compatibility জানুন
| Platform | VBA Macro | নোট |
|---|---|---|
| Excel for Windows Desktop | হ্যাঁ | VBA Automation-এর সবচেয়ে পূর্ণ Desktop Environment। |
| Excel for Mac Desktop | হ্যাঁ, কিছু সীমাবদ্ধতা আছে | Windows-specific COM/ActiveX/Windows API Code সরাসরি কাজ নাও করতে পারে। |
| Excel for the Web | চালানো/তৈরি/এডিট করা যায় না | Macro-যুক্ত Workbook খুলে দেখা যায়; Macro চালাতে Desktop App ব্যবহার করুন। |
| Excel Mobile (iOS/Android) | VBA Macro রান নয় | Mobile Excel-কে VBA Execution Environment ধরে Design করবেন না। |
এই Article-এর অধিকাংশ VBA Code Excel Desktop-এর জন্য। Excel Web-এ Automation দরকার হলে Office Scripts ও Power Automate-এর পথ দেখুন। Macro-সহ Workbook সাধারণত .xlsm অথবা .xlsb Format-এ Save করতে হয়। .xlsx Format-এ VBA Project রাখা যায় না—Save করার সময় Macro বাদ পড়তে পারে।
3. Developer Tab, VBA Editor ও প্রথম Setup
3.1 Developer Tab Enable করুন (Windows)
- Excel Open করুন।
- File → Options-এ যান।
- Customize Ribbon নির্বাচন করুন।
- Main Tabs-এর মধ্যে Developer-এ Tick দিন।
- OK চাপুন।
3.2 VBA Editor Open করুন
Keyboard Shortcut Alt + F11 চাপলে Visual Basic Editor (VBE) খুলবে। Developer → Visual Basic দিয়েও খুলতে পারবেন। Macro List দেখতে Alt + F8 ব্যবহার করুন।
3.3 Macro Workbook হিসেবে Save করুন
- File → Save As নির্বাচন করুন।
- Save as type থেকে Excel Macro-Enabled Workbook (*.xlsm) বেছে নিন।
- File Save করুন।
- পরীক্ষার জন্য আগে একটি Copy/Backup রেখে কাজ করুন।
.xlsx Workbook VBA Macro সংরক্ষণ করে না। VBA-সহ Workbook-এর জন্য .xlsm সবচেয়ে প্রচলিত Format; Excel Binary Macro-Enabled Workbook .xlsb এবং Excel Add-in .xlam-ও Macro সমর্থন করে।3.4 Macro কোথায় Store করবেন?
| Storage | কোথায় ব্যবহার করবেন | মনে রাখবেন |
|---|---|---|
| This Workbook (.xlsm) | শুধু এই Workbook-এর Automation | Workbook অন্য User-কে দিলে Macro একই File-এ থাকবে। |
| Personal Macro Workbook (PERSONAL.XLSB) | নিজের Excel Desktop-এ সব Workbook-এ বারবার ব্যবহারযোগ্য Macro | Record Macro Dialog-এ Store Macro In → Personal Macro Workbook বেছে নিন। এটি Local User Profile-এর Excel Startup Workbook। |
| Excel Add-in (.xlam) | একাধিক Workbook/Team-এর জন্য Reusable Tool | Install/Enable করতে হয়; Distribution ও Macro Security Policy মানতে হয়। |
Personal.xlsb তৈরি করার ধাপ: Developer → Record Macro → Store Macro In থেকে Personal Macro Workbook নির্বাচন করুন → একটি ছোট Action Record করুন → Stop Recording → Excel Close করার সময় Personal Macro Workbook Save Prompt এলে Save দিন। পরে Macro List থেকে Personal.xlsb-এর Macro ব্যবহার করতে পারবেন।
4. Macro Recorder — Coding ছাড়াই প্রথম Automation
Macro Recorder আপনার Mouse Click ও Keyboard Action Record করে VBA Code তৈরি করে। এটি শেখার দ্রুততম উপায়, তবে Recorded Code-এ অনেক Select/Activate থাকতে পারে। পরে Code Edit করে সেটিকে নির্ভরযোগ্য ও দ্রুত করা দরকার।
4.1 Step-by-Step: Daily Report Formatting Record
- Developer → Record Macro চাপুন।
- Macro Name দিন:
Format_Daily_Report। Space ব্যবহার করবেন না; নাম Letter দিয়ে শুরু করুন। - Shortcut Key চাইলে দিন; আগে ব্যবহৃত গুরুত্বপূর্ণ Shortcut যেন Override না হয়।
- Description-এ Macro কী করবে লিখুন।
- Header Bold, Fill Colour, Number Format, Column Width, Border ইত্যাদি Format করুন।
- Developer → Stop Recording চাপুন।
- Alt + F8 → Macro Select → Edit দিয়ে VBA Code দেখুন।
4.2 Record করা Macro-এর Example
Sub Format_Daily_Report()
' Header format
With ThisWorkbook.Worksheets("Report").Range("A1:F1")
.Font.Bold = True
.Interior.Color = RGB(31, 78, 121)
.Font.Color = RGB(255, 255, 255)
.HorizontalAlignment = xlCenter
End With
' Adjust columns
ThisWorkbook.Worksheets("Report").Columns("A:F").AutoFit
End SubCode-এর শুরুতে Sub এবং শেষে End Sub থাকে। মাঝখানে Excel-কে নির্দেশ দেওয়া হয়। VBA Code-এ Apostrophe ' দিয়ে Comment লেখা যায়; Comment Macro Execute হয় না।
5. Visual Basic Editor (VBE) — কোন জায়গায় কোন Code লিখবেন?
| VBE অংশ | কাজ | Code-এর ধরন |
|---|---|---|
| Project Explorer | Workbook, Sheet, ThisWorkbook, Modules দেখায় | কোন Object কোথায় আছে বোঝা |
| Standard Module | সাধারণ Macro ও Function রাখে | Sub / Function |
| Sheet Module | নির্দিষ্ট Worksheet-এর Event Code | Worksheet_Change, Worksheet_SelectionChange |
| ThisWorkbook | Workbook Open/BeforeClose/Sheet Events | Workbook_Open, Workbook_BeforeClose |
| UserForm | নিজস্ব Data Entry Form ও Controls | CommandButton_Click, TextBox ইত্যাদি |
| Immediate Window | ছোট Test/Debug Command চালায় | Debug.Print, ? variable |
5.1 Standard Module Insert করুন
- Alt + F11 চাপুন।
- Insert → Module নির্বাচন করুন।
- ডান পাশের Code Window-তে Code Paste করুন।
- Ctrl + S দিয়ে Save করুন।
- VBE-তে Cursor Macro-এর ভিতরে রেখে F5 চাপুন, অথবা Excel-এ Alt + F8 দিয়ে Run করুন।
Sub Macro Standard Module-এ। Worksheet_Change সংশ্লিষ্ট Sheet-এর Code Window-তে। Workbook_Open ThisWorkbook-এ। Event Code ভুল Module-এ রাখলে Event কাজ করবে না।6. VBA Programming Basics — Beginner থেকে Intermediate
6.1 Option Explicit — ভুল Variable Name আটকান
Option Explicit
Sub FirstMacro()
Dim employeeName As String
Dim totalQty As Long
employeeName = "Operator A"
totalQty = 125
MsgBox "Operator: " & employeeName & vbCrLf & _
"Total Qty: " & totalQty
End SubOption Explicit দিলে Variable ব্যবহার করার আগে Declare করতে হয়। এতে Typing Mistake কমে। Dim দিয়ে Variable তৈরি হয়; String Text, Long Whole Number, Double Decimal, Date Date/Time, Boolean True/False এবং Object Excel Object-এর জন্য ব্যবহার হয়।
| Data Type | Example | ব্যবহার |
|---|---|---|
| String | "Battery" | Text, Product Name, ID |
| Long | 25000 | Row Number, Count, Integer |
| Double | 12.75 | Decimal, Measurement, Amount |
| Date | Date | Date/Time |
| Boolean | True | Condition Flag |
| Variant | Variant | Mixed/Unknown Value; অতিরিক্ত ব্যবহার এড়িয়ে চলুন |
| Worksheet | Worksheet | Sheet Object Reference |
| Workbook | Workbook | Workbook Object Reference |
| Range | Range | Cell/Cell Range Reference |
6.2 If...Then...Else — Condition
Sub CheckTestResult()
Dim result As String
result = UCase$(Trim$(ThisWorkbook.Worksheets("RawData").Range("C2").Value))
If result = "PASS" Then
ThisWorkbook.Worksheets("RawData").Range("D2").Value = "OK"
ElseIf result = "FAIL" Then
ThisWorkbook.Worksheets("RawData").Range("D2").Value = "REPAIR"
Else
ThisWorkbook.Worksheets("RawData").Range("D2").Value = "CHECK DATA"
End If
End Sub6.3 For Loop — একাধিক Row-তে কাজ
Sub MarkFailedRows()
Dim ws As Worksheet
Dim lastRow As Long
Dim r As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
For r = 2 To lastRow
If UCase$(Trim$(CStr(ws.Cells(r, "C").Value))) = "FAIL" Then
ws.Cells(r, "D").Value = "REPAIR"
ElseIf UCase$(Trim$(CStr(ws.Cells(r, "C").Value))) = "PASS" Then
ws.Cells(r, "D").Value = "OK"
End If
Next r
End Sub6.4 Do While / Do Until — Condition যতক্ষণ সত্য
Sub FillSerialNumbers()
Dim ws As Worksheet
Dim r As Long
Set ws = ThisWorkbook.Worksheets("RawData")
r = 2
Do While Len(ws.Cells(r, "B").Value) > 0
ws.Cells(r, "A").Value = r - 1
r = r + 1
Loop
End Sub6.5 Select Case — অনেক Status-এর জন্য
Sub AssignPriority()
Dim ws As Worksheet, r As Long, lastRow As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
For r = 2 To lastRow
Select Case UCase$(Trim$(CStr(ws.Cells(r, "C").Value)))
Case "CRITICAL": ws.Cells(r, "D").Value = "P1"
Case "HIGH": ws.Cells(r, "D").Value = "P2"
Case "MEDIUM": ws.Cells(r, "D").Value = "P3"
Case "LOW": ws.Cells(r, "D").Value = "P4"
Case Else: ws.Cells(r, "D").Value = "REVIEW"
End Select
Next r
End Sub6.6 Function — নিজের Custom Function
Option Explicit
Public Function YieldRate(ByVal passQty As Double, _
ByVal totalQty As Double) As Variant
If totalQty <= 0 Then
YieldRate = CVErr(xlErrDiv0)
Else
YieldRate = passQty / totalQty
End If
End Functionএখন Worksheet-এ ব্যবহার করুন: =YieldRate(B2,C2)। Cell-কে Percentage Format দিন। Worksheet UDF সাধারণত Calculation-এর জন্য ব্যবহার করুন; অন্য Cell-এ Write, Format পরিবর্তন বা File Save করার মতো Side Effect UDF-এর মধ্যে রাখবেন না।
7. Workbook, Worksheet, Range, Cells — VBA Object Model
VBA-তে Excel-এর Workbook, Worksheet, Range, Chart, PivotTable—সবকিছুকে Object হিসেবে ধরা হয়। সবচেয়ে জরুরি অভ্যাস হলো সবসময় Workbook ও Worksheet স্পষ্টভাবে লিখুন; শুধু Range("A1") লিখে Active Sheet-এর উপর নির্ভর করবেন না।
Sub ObjectModelExample()
Dim wb As Workbook
Dim ws As Worksheet
Dim target As Range
Set wb = ThisWorkbook
Set ws = wb.Worksheets("RawData")
Set target = ws.Range("A1:C10")
target.Font.Name = "Arial"
target.Columns.AutoFit
ws.Range("A1").Value = "Product ID"
End Sub| Reference | অর্থ | Example |
|---|---|---|
| ThisWorkbook | যে Workbook-এ Code আছে | ThisWorkbook.Worksheets("Report") |
| ActiveWorkbook | বর্তমানে Active Workbook | ActiveWorkbook.Name |
| ActiveSheet | বর্তমানে Active Sheet | ActiveSheet.Range("A1") |
| Worksheets("Name") | নির্দিষ্ট Worksheet | Worksheets("RawData") |
| Range("A1") | Cell/Range Address | Range("A1:D20") |
| Cells(row, col) | Row/Column Number দিয়ে Cell | Cells(2, 3) = C2 |
| Offset(r,c) | বর্তমান Range থেকে সরুন | Range("B2").Offset(0,1) = C2 |
| End(xlUp) | Column-এর শেষ Filled Cell | Cells(Rows.Count,"A").End(xlUp).Row |
7.1 Last Used Row বের করা
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Rowএখানে ws.Rows.Count হলো Worksheet-এর মোট Row সংখ্যা; Bottom থেকে End(xlUp) দিয়ে উপরের শেষ Filled Cell খুঁজে Row Number পাওয়া যায়। Column A-তে ফাঁকা থাকলে আপনার Data-এর সবচেয়ে নির্ভরযোগ্য Key Column ব্যবহার করুন।
7.2 CurrentRegion ও Excel Table
Dim dataRange As Range
Set dataRange = ThisWorkbook.Worksheets("RawData").Range("A1").CurrentRegion
MsgBox "Data Rows: " & dataRange.Rows.Countযদি Data-র চারপাশে ফাঁকা Row/Column থাকে, CurrentRegion-এর Result ছোট হয়ে যেতে পারে। Production-Grade Workflow-এ Excel Table (ListObject) এবং Named Range ব্যবহার করা বেশি নির্ভরযোগ্য।
8. দরকারি VBA Patterns — বারবার কাজে লাগবে
With ThisWorkbook.Worksheets("Report").Range("A1:F1")
.Font.Bold = True
.Interior.Color = RGB(31, 78, 121)
.Font.Color = vbWhite
.HorizontalAlignment = xlCenter
End WithSub ArrayExample()
Dim ws As Worksheet
Dim data As Variant
Set ws = ThisWorkbook.Worksheets("RawData")
data = ws.Range("A1:D1000").Value2
' Array indexing: data(row, column)
data(2, 4) = "CHECKED"
ws.Range("A1:D1000").Value2 = data
End Subবড় Data-তে প্রতিটি Cell-এ আলাদা আলাদা Read/Write না করে Range-কে Array-তে নিয়ে Process করে একবারে ফেরত Write করলে Macro দ্রুত হতে পারে। Array-র প্রথম Dimension Row এবং দ্বিতীয় Dimension Column।
Sub InsertFormulas()
Dim ws As Worksheet, lastRow As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
If lastRow < 2 Then Exit Sub
ws.Range("A2:A" & lastRow).Formula = "=IF(B2="""","""",ROW()-1)"
ws.Range("D2:D" & lastRow).Formula = "=IF(C2=""PASS"",""OK"",IF(C2=""FAIL"",""REPAIR"",""CHECK""))"
End SubRange.Formula ব্যবহার করলে সাধারণত English Function Name ও comma separator ব্যবহার করুন; FormulaLocal স্থানীয় Excel Language/Separator অনুসরণ করে। Microsoft 365-এর Dynamic Array Formula-র জন্য Formula2 আছে, তবে পুরনো Excel Version-এ Compatibility যাচাই করুন।9. Practical Automation: Data Cleaning & Formatting
9.1 One-Click Professional Report Formatting
ধরা যাক RawData Sheet-এ A:F পর্যন্ত Header আছে। এই Macro Header Format, Filter, Freeze Pane ও Column Width ঠিক করবে। Freeze Pane-এর Active Window নির্ভরতা এড়াতে আগে A2 Select করা হয়েছে।
Option Explicit
Sub FormatReport()
Dim ws As Worksheet, lastRow As Long, lastCol As Long
Set ws = ThisWorkbook.Worksheets("RawData")
If Application.WorksheetFunction.CountA(ws.Cells) = 0 Then Exit Sub
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
With ws.Range(ws.Cells(1, 1), ws.Cells(1, lastCol))
.Font.Bold = True
.Font.Color = vbWhite
.Interior.Color = RGB(31, 78, 121)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
End With
ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol)).Borders.LineStyle = xlContinuous
ws.Columns(1).Resize(, lastCol).AutoFit
If ws.AutoFilterMode Then ws.AutoFilterMode = False
ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol)).AutoFilter
ws.Activate
ws.Range("A2").Select
ActiveWindow.FreezePanes = True
MsgBox "Report formatting completed.", vbInformation
End Sub9.2 Extra Space ও Non-printing Character Clean
Sub CleanTextColumns()
Dim ws As Worksheet, lastRow As Long, r As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
For r = 2 To lastRow
If Not IsError(ws.Cells(r, "B").Value) Then
ws.Cells(r, "B").Value = Application.WorksheetFunction.Trim( _
WorksheetFunction.Clean(CStr(ws.Cells(r, "B").Value)))
End If
Next r
MsgBox "Text cleaning completed.", vbInformation
End Subএই Macro Column B-তে থাকা Text-এর শুরু/শেষের এবং অতিরিক্ত সাধারণ Space কমায়; CLEAN দিয়ে কিছু Non-printing Character সরায়। Original Data-র Copy রেখে পরীক্ষা করুন।
9.3 Duplicate Row Remove
Sub RemoveDuplicateRecords()
Dim ws As Worksheet, lastRow As Long, lastCol As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
If lastRow < 2 Then Exit Sub
ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol)).RemoveDuplicates _
Columns:=Array(1, 2), Header:=xlYes
End Subএখানে Columns:=Array(1,2) মানে নির্বাচিত Range-এর প্রথম ও দ্বিতীয় Column মিলিয়ে Duplicate নির্ধারণ হবে। আপনার Unique Key অনুযায়ী Column Index বদলান। RemoveDuplicates স্থায়ীভাবে Row মুছে দেয়—আগে Backup নিন।
9.4 Blank Row Remove
Sub DeleteBlankKeyRows()
Dim ws As Worksheet, lastRow As Long, r As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For r = lastRow To 2 Step -1
If Len(Trim$(CStr(ws.Cells(r, "A").Value))) = 0 Then
ws.Rows(r).Delete
End If
Next r
End SubBottom থেকে Top-এ Loop করা হয়েছে, কারণ Row Delete করলে নিচের Row-এর Index উপরে উঠে যায়।
10. Formula, Calculation ও Automatic Status
10.1 Formula Fill Down
Sub FillReportFormulas()
Dim ws As Worksheet, lastRow As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
If lastRow < 2 Then Exit Sub
ws.Range("A2:A" & lastRow).Formula = "=IF(B2="""","""",ROW()-1)"
ws.Range("D2:D" & lastRow).Formula = "=IF(C2=""PASS"",""OK"",IF(C2=""FAIL"",""REPAIR"",""PENDING""))"
ws.Range("E2:E" & lastRow).Formula = "=IF(B2="""","""",TODAY())"
ws.Range("E2:E" & lastRow).NumberFormat = "dd-mmm-yyyy"
End SubNow Value লিখুন (পরবর্তী Event Section দেখুন)।10.2 COUNTIF / SUMIF-ধরনের Summary VBA দিয়ে
Sub BuildQualitySummary()
Dim ws As Worksheet, rpt As Worksheet, lastRow As Long
Set ws = ThisWorkbook.Worksheets("RawData")
Set rpt = ThisWorkbook.Worksheets("Summary")
lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
rpt.Range("A1:B4").ClearContents
rpt.Range("A1").Value = "Metric"
rpt.Range("B1").Value = "Count"
rpt.Range("A2").Value = "Total Records"
rpt.Range("B2").Value = Application.WorksheetFunction.CountA(ws.Range("B2:B" & lastRow))
rpt.Range("A3").Value = "Pass"
rpt.Range("B3").Value = Application.WorksheetFunction.CountIf(ws.Range("C2:C" & lastRow), "Pass")
rpt.Range("A4").Value = "Fail"
rpt.Range("B4").Value = Application.WorksheetFunction.CountIf(ws.Range("C2:C" & lastRow), "Fail")
rpt.Columns("A:B").AutoFit
End SubFormula দিয়েও COUNTIF/SUMIF/COUNTIFS/SUMIFS/AVERAGEIFS করা যায়। Macro-র ভিতর Application.WorksheetFunction দিয়ে Worksheet Function কল করা হয়। Error Return করতে পারে এমন Function-এর ক্ষেত্রে Error Handling রাখুন।
11. Sort, Filter, Pass/Fail Split ও Row Classification
11.1 Data Sort
Sub SortByDate()
Dim ws As Worksheet, lastRow As Long, lastCol As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
If lastRow < 2 Then Exit Sub
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=ws.Range("A2:A" & lastRow), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
End Sub11.2 Fail Records আলাদা Sheet-এ Copy
Sub CopyFailedRecords()
Dim src As Worksheet, dest As Worksheet
Dim lastRow As Long, lastCol As Long, r As Long, nextRow As Long
Set src = ThisWorkbook.Worksheets("RawData")
Set dest = ThisWorkbook.Worksheets("FailRecords")
lastRow = src.Cells(src.Rows.Count, "A").End(xlUp).Row
lastCol = src.Cells(1, src.Columns.Count).End(xlToLeft).Column
dest.Cells.Clear
src.Range(src.Cells(1, 1), src.Cells(1, lastCol)).Copy dest.Cells(1, 1)
nextRow = 2
For r = 2 To lastRow
If UCase$(Trim$(CStr(src.Cells(r, "C").Value))) = "FAIL" Then
src.Range(src.Cells(r, 1), src.Cells(r, lastCol)).Copy dest.Cells(nextRow, 1)
nextRow = nextRow + 1
End If
Next r
dest.Columns.AutoFit
MsgBox (nextRow - 2) & " failed records copied.", vbInformation
End Sub11.3 Filter Apply / Clear Filter
Sub FilterFailedRows()
Dim ws As Worksheet, lastRow As Long, lastCol As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
If ws.AutoFilterMode Then ws.AutoFilterMode = False
ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol)).AutoFilter _
Field:=3, Criteria1:="FAIL"
End Sub
Sub ClearReportFilter()
With ThisWorkbook.Worksheets("RawData")
If .FilterMode Then .ShowAllData
End With
End Sub12. Folder ও Multiple Excel File Automation
এটি Advanced Excel Automation-এর অন্যতম গুরুত্বপূর্ণ ব্যবহার। ধরুন Folder-এর মধ্যে প্রতিদিন/প্রতি সপ্তাহে আলাদা Excel File জমা হচ্ছে, এবং আপনি সেগুলির Data Master Workbook-এ Combine করতে চান। File Path, Sheet Name, Header Layout ও Column Structure আগে Standardize করুন।
12.1 একটি Source Workbook থেকে নির্দিষ্ট Cell অন্য Workbook-এ Copy
Sub ReadCellFromOtherWorkbook()
Dim sourcePath As String
Dim srcWb As Workbook, srcWs As Worksheet
Dim destWs As Worksheet
sourcePath = "C:\Data\Source\Master_Data.xlsx"
Set destWs = ThisWorkbook.Worksheets("Report")
If Dir(sourcePath) = "" Then
MsgBox "Source file not found: " & sourcePath, vbExclamation
Exit Sub
End If
Application.ScreenUpdating = False
On Error GoTo CleanFail
Set srcWb = Workbooks.Open(Filename:=sourcePath, ReadOnly:=True, UpdateLinks:=False)
Set srcWs = srcWb.Worksheets("Sheet1")
destWs.Range("B2").Value = srcWs.Range("C5").Value
srcWb.Close SaveChanges:=False
Set srcWb = Nothing
Application.ScreenUpdating = True
MsgBox "Value imported successfully.", vbInformation
Exit Sub
CleanFail:
On Error Resume Next
If Not srcWb Is Nothing Then srcWb.Close SaveChanges:=False
Application.ScreenUpdating = True
MsgBox "Import failed: " & Err.Description, vbCritical
End Sub12.2 একই Folder-এর সব Excel File থেকে Data Combine
Option Explicit
Sub CombineExcelFilesInFolder()
Dim folderPath As String, fileName As String
Dim srcWb As Workbook, srcWs As Worksheet, destWs As Worksheet
Dim srcLastRow As Long, srcLastCol As Long, destNextRow As Long
Dim firstFile As Boolean
folderPath = "C:\Data\MonthlyFiles\" ' শেষে backslash দিন
Set destWs = ThisWorkbook.Worksheets("Master")
firstFile = True
If Right$(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
If Dir(folderPath, vbDirectory) = "" Then
MsgBox "Folder not found.", vbExclamation
Exit Sub
End If
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error GoTo CleanFail
destWs.Cells.Clear
fileName = Dir(folderPath & "*.xlsx")
Do While Len(fileName) > 0
If StrComp(folderPath & fileName, ThisWorkbook.FullName, vbTextCompare) <> 0 Then
Set srcWb = Workbooks.Open(folderPath & fileName, ReadOnly:=True, UpdateLinks:=False)
Set srcWs = srcWb.Worksheets("Data")
srcLastRow = srcWs.Cells(srcWs.Rows.Count, "A").End(xlUp).Row
srcLastCol = srcWs.Cells(1, srcWs.Columns.Count).End(xlToLeft).Column
If srcLastRow >= 1 And srcLastCol >= 1 Then
If firstFile Then
srcWs.Range(srcWs.Cells(1, 1), srcWs.Cells(srcLastRow, srcLastCol)).Copy _
destWs.Cells(1, 1)
firstFile = False
ElseIf srcLastRow >= 2 Then
destNextRow = destWs.Cells(destWs.Rows.Count, "A").End(xlUp).Row + 1
srcWs.Range(srcWs.Cells(2, 1), srcWs.Cells(srcLastRow, srcLastCol)).Copy _
destWs.Cells(destNextRow, 1)
End If
End If
srcWb.Close SaveChanges:=False
Set srcWb = Nothing
End If
fileName = Dir()
Loop
destWs.Columns.AutoFit
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "File consolidation completed.", vbInformation
Exit Sub
CleanFail:
On Error Resume Next
If Not srcWb Is Nothing Then srcWb.Close SaveChanges:=False
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "Consolidation stopped: " & Err.Description, vbCritical
End Subএই Code ধরে নিচ্ছে প্রতিটি Source Workbook-এ Data নামে Sheet আছে এবং একই Column Structure রয়েছে। এটি .xlsx Files খোঁজে; .xlsm/.xlsb/.csv হলে Pattern ও Import Logic বদলাতে হবে। Destination Master File-টি Input Folder-এর বাইরে রাখুন।
12.3 CSV Folder Import — Power Query কখন ভালো?
Sub ImportCsvFilesOneByOne()
Dim folderPath As String, fileName As String
Dim csvWb As Workbook, destWs As Worksheet
Dim sourceWs As Worksheet, lastRow As Long, lastCol As Long, nextRow As Long
folderPath = "C:\Data\CSV\"
Set destWs = ThisWorkbook.Worksheets("CSV_Master")
If Right$(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
Application.ScreenUpdating = False
On Error GoTo CleanFail
fileName = Dir(folderPath & "*.csv")
Do While Len(fileName) > 0
Workbooks.OpenText Filename:=folderPath & fileName, _
DataType:=xlDelimited, Comma:=True, Local:=True
Set csvWb = ActiveWorkbook
Set sourceWs = csvWb.Worksheets(1)
lastRow = sourceWs.Cells(sourceWs.Rows.Count, 1).End(xlUp).Row
lastCol = sourceWs.Cells(1, sourceWs.Columns.Count).End(xlToLeft).Column
If destWs.Cells(1, 1).Value = "" Then
sourceWs.Range(sourceWs.Cells(1, 1), sourceWs.Cells(lastRow, lastCol)).Copy destWs.Range("A1")
ElseIf lastRow >= 2 Then
nextRow = destWs.Cells(destWs.Rows.Count, 1).End(xlUp).Row + 1
sourceWs.Range(sourceWs.Cells(2, 1), sourceWs.Cells(lastRow, lastCol)).Copy _
destWs.Cells(nextRow, 1)
End If
csvWb.Close SaveChanges:=False
Set csvWb = Nothing
fileName = Dir()
Loop
destWs.Columns.AutoFit
Application.ScreenUpdating = True
MsgBox "CSV import completed.", vbInformation
Exit Sub
CleanFail:
On Error Resume Next
If Not csvWb Is Nothing Then csvWb.Close SaveChanges:=False
Application.ScreenUpdating = True
MsgBox "CSV import error: " & Err.Description, vbCritical
End Sub12.4 File Dialog দিয়ে User-কে Folder Select করতে দিন
Function PickFolder() As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Source Folder"
.AllowMultiSelect = False
If .Show = -1 Then PickFolder = .SelectedItems(1)
End With
End Function
Sub ShowSelectedFolder()
Dim folderPath As String
folderPath = PickFolder()
If Len(folderPath) = 0 Then
MsgBox "No folder selected."
Else
MsgBox folderPath
End If
End Sub13. Report, PDF, Print & Backup Automation
13.1 One-Click PDF Export
Sub ExportReportToPDF()
Dim ws As Worksheet, pdfPath As String
Set ws = ThisWorkbook.Worksheets("Report")
If Len(ThisWorkbook.Path) = 0 Then
MsgBox "আগে Workbook Save করুন।", vbExclamation
Exit Sub
End If
With ws.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 0
.CenterHorizontally = True
End With
pdfPath = ThisWorkbook.Path & "\Report_" & Format(Now, "yyyymmdd_hhnnss") & ".pdf"
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
MsgBox "PDF saved: " & pdfPath, vbInformation
End Sub13.2 Workbook Backup তৈরি
Sub CreateWorkbookBackup()
Dim backupFolder As String, backupName As String
Dim extensionPos As Long
If Len(ThisWorkbook.Path) = 0 Then
MsgBox "আগে Workbook Save করুন।", vbExclamation
Exit Sub
End If
backupFolder = ThisWorkbook.Path & "\Backup"
If Dir(backupFolder, vbDirectory) = "" Then MkDir backupFolder
extensionPos = InStrRev(ThisWorkbook.Name, ".")
backupName = backupFolder & "\" & _
Left$(ThisWorkbook.Name, extensionPos - 1) & _
"_" & Format(Now, "yyyymmdd_hhnnss") & _
Mid$(ThisWorkbook.Name, extensionPos)
ThisWorkbook.SaveCopyAs backupName
MsgBox "Backup created: " & backupName, vbInformation
End SubBackup Folder আগে থেকে থাকলে Code নতুন Folder তৈরি করবে না। SaveCopyAs বর্তমান Workbook-এর Format অনুসারে Copy তৈরি করে; আসল Workbook-এর নাম/Location পরিবর্তন করে না।
13.3 Selected Sheet আলাদা XLSX হিসেবে Export
Sub ExportReportAsXLSX()
Dim ws As Worksheet, newWb As Workbook, savePath As String
Set ws = ThisWorkbook.Worksheets("Report")
If Len(ThisWorkbook.Path) = 0 Then
MsgBox "আগে Workbook Save করুন।", vbExclamation
Exit Sub
End If
savePath = ThisWorkbook.Path & "\Report_Export_" & Format(Date, "yyyymmdd") & ".xlsx"
ws.Copy
Set newWb = ActiveWorkbook
Application.DisplayAlerts = False
newWb.SaveAs Filename:=savePath, FileFormat:=xlOpenXMLWorkbook
newWb.Close SaveChanges:=False
Application.DisplayAlerts = True
MsgBox "XLSX export completed.", vbInformation
End Sub13.4 Print Area ও Page Setup
Sub PreparePrintLayout()
Dim ws As Worksheet, lastRow As Long, lastCol As Long
Set ws = ThisWorkbook.Worksheets("Report")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
With ws.PageSetup
.PrintArea = ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol)).Address
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.CenterHorizontally = True
.FitToPagesWide = 1
.FitToPagesTall = 0
.Zoom = False
End With
End Sub14. Chart, PivotTable ও Dashboard Automation
14.1 VBA দিয়ে Dynamic Chart Create
Sub CreateOutputChart()
Dim ws As Worksheet, lastRow As Long
Dim chartObj As ChartObject
Set ws = ThisWorkbook.Worksheets("Summary")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
If lastRow < 2 Then Exit Sub
' Remove old chart with same name if it exists
On Error Resume Next
ws.ChartObjects("chtMonthlyOutput").Delete
On Error GoTo 0
Set chartObj = ws.ChartObjects.Add(Left:=300, Top:=20, Width:=520, Height:=300)
chartObj.Name = "chtMonthlyOutput"
With chartObj.Chart
.SetSourceData Source:=ws.Range("A1:B" & lastRow)
.ChartType = xlColumnClustered
.HasTitle = True
.ChartTitle.Text = "Monthly Output"
.HasLegend = False
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Text = "Month"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Text = "Quantity (Pcs)"
End With
End Sub14.2 PivotTable Refresh ও Refresh All
Sub RefreshAllReports()
Dim ws As Worksheet, pt As PivotTable
ThisWorkbook.RefreshAll
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws
MsgBox "Refresh commands completed. Query refresh may continue in background depending on connection settings.", vbInformation
End Subকিছু Power Query/External Connection Background-এ Refresh হতে পারে। Dashboard PDF Export বা KPI Recalculation-এর আগে Refresh Completion নিশ্চিত করার জন্য Connection Properties ও Asynchronous Query আচরণ বুঝে নিন। Excel Version অনুযায়ী Application.CalculateUntilAsyncQueriesDone সহায়ক হতে পারে; সব Connection Type-এ একই আচরণ ধরে নেবেন না।
14.3 Slicer ও Timeline কেন দরকার?
- PivotTable/PivotChart-এ Department, Month, Product, Shift অনুযায়ী Interactive Filtering করতে Slicer ব্যবহার করুন।
- Date/Month/Quarter/Year ভিত্তিক Pivot Filter সহজ করতে Timeline ব্যবহার করুন।
- Dashboard-এ Raw Data Table সরাসরি Chart Source না করে Pivot/Summary Table বা Excel Table ব্যবহার করুন।
- Macro দিয়ে Pivot Refresh করা যায়; Slicer-এর Selection এবং Dashboard Layout আলাদা করে Design করতে হয়।
আপনার Site-এর Excel Charts Complete Master Guide পড়ুন—সেখানে Chart Selection, Advanced Axis, Trendline, Error Bar, Dynamic Chart ও Dashboard Design বিস্তারিত ব্যাখ্যা করা হয়েছে।
15. Event Automation — Cell Change হলেই Macro Run
Normal Macro-তে User-কে Alt+F8 বা Button দিয়ে Run করতে হয়। Event Procedure নির্দিষ্ট ঘটনা ঘটলে নিজে থেকে Execute হয়—যেমন Workbook Open, Worksheet Cell Change, Workbook Before Close। Event Code সংশ্লিষ্ট Sheet/ThisWorkbook Module-এ লিখতে হয়।
15.1 Status Cell Automatically Update
ধরুন RawData Sheet-এ Column C-তে Test Result (Pass/Fail) লিখবেন, Column D-তে Status Automatically আসবে।
Private Sub Worksheet_Change(ByVal Target As Range)
Dim hit As Range, cell As Range
On Error GoTo CleanFail
Set hit = Intersect(Target, Me.Range("C2:C5000"))
If hit Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each cell In hit.Cells
Select Case UCase$(Trim$(CStr(cell.Value)))
Case "PASS": Me.Cells(cell.Row, "D").Value = "OK"
Case "FAIL": Me.Cells(cell.Row, "D").Value = "REPAIR"
Case Else: Me.Cells(cell.Row, "D").ClearContents
End Select
Next cell
CleanExit:
Application.EnableEvents = True
Exit Sub
CleanFail:
MsgBox "Status automation error: " & Err.Description, vbExclamation
Resume CleanExit
End Sub15.2 Data Entry-র সময় Permanent Timestamp
Private Sub Worksheet_Change(ByVal Target As Range)
Dim hit As Range, cell As Range
On Error GoTo CleanFail
Set hit = Intersect(Target, Me.Range("B2:B5000"))
If hit Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each cell In hit.Cells
If Len(cell.Value) > 0 Then
If Len(Me.Cells(cell.Row, "E").Value) = 0 Then
Me.Cells(cell.Row, "E").Value = Now
Me.Cells(cell.Row, "E").NumberFormat = "dd-mmm-yyyy hh:mm"
End If
Else
Me.Cells(cell.Row, "E").ClearContents
End If
Next cell
CleanExit:
Application.EnableEvents = True
Exit Sub
CleanFail:
MsgBox Err.Description, vbExclamation
Resume CleanExit
End Subএই উদাহরণে Column B-তে নতুন Data দিলে Column E-তে প্রথম Entry Time বসে। পরে B পরিবর্তন করলেও E-র আগের Timestamp থাকে। প্রতিটি Edit-এর সময় Timestamp Update করতে চাইলে If Len(...)=0 Then Condition বাদ দিয়ে সরাসরি Now বসান।
16. Button, InputBox, Message Box ও UserForm
16.1 Worksheet-এ Button বসিয়ে Macro চালানো
- Developer → Insert → Form Controls → Button নির্বাচন করুন।
- Worksheet-এ Button Draw করুন।
- Assign Macro Window থেকে Macro Select করুন।
- Button-এর Text Edit করে “Generate Report” বা “Export PDF” লিখুন।
- Button Click করে Test করুন।
16.2 InputBox দিয়ে User-এর কাছ থেকে Value নিন
Sub SearchProductPrompt()
Dim productID As String
Dim ws As Worksheet, foundCell As Range
Set ws = ThisWorkbook.Worksheets("RawData")
productID = Trim$(InputBox("Enter Product ID:", "Search Product"))
If Len(productID) = 0 Then Exit Sub
Set foundCell = ws.Columns("A").Find(What:=productID, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If foundCell Is Nothing Then
MsgBox "Product ID not found.", vbExclamation
Else
MsgBox "Product found at Row: " & foundCell.Row, vbInformation
ws.Activate
foundCell.Select
End If
End Sub16.3 UserForm দিয়ে ছোট Data Entry Application
UserForm ব্যবহার করলে Excel-এ TextBox, ComboBox, ListBox, Label ও Button দিয়ে নিজের Entry Form তৈরি করা যায়। VBE → Insert → UserForm; Toolbox থেকে Controls যোগ করুন। নিচের Save Button Code ধরে নিচ্ছে UserForm-এ txtProductID, txtProductName, cboResult এবং cmdSave নামে Controls আছে।
Private Sub cmdSave_Click()
Dim ws As Worksheet, nextRow As Long
Set ws = ThisWorkbook.Worksheets("RawData")
If Trim$(Me.txtProductID.Value) = "" Then
MsgBox "Product ID is required.", vbExclamation
Me.txtProductID.SetFocus
Exit Sub
End If
nextRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
ws.Cells(nextRow, "A").Value = Trim$(Me.txtProductID.Value)
ws.Cells(nextRow, "B").Value = Trim$(Me.txtProductName.Value)
ws.Cells(nextRow, "C").Value = UCase$(Trim$(Me.cboResult.Value))
ws.Cells(nextRow, "E").Value = Now
MsgBox "Record saved successfully.", vbInformation
Me.txtProductID.Value = ""
Me.txtProductName.Value = ""
Me.cboResult.Value = ""
Me.txtProductID.SetFocus
End SubSub OpenEntryForm()
UserForm1.Show
End SubUserForm-এর নাম পরিবর্তন করলে Code-এর UserForm1 অংশে সেই নাম দিন। ComboBox-এর List/Validation Initialize Event-এ Load করুন। Form-এ Save করার আগে ID Duplicate কিনা Check করাও ভালো।
17. Advanced Automation — আরও কিছু Real Office Use Case
17.1 Data Validation Dropdown তৈরি
Sub AddResultDropdown()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("RawData")
With ws.Range("C2:C5000").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="Pass,Fail,Pending"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Test Result"
.InputMessage = "Select Pass, Fail or Pending"
.ErrorTitle = "Invalid Result"
.ErrorMessage = "Dropdown থেকে একটি Value Select করুন।"
.ShowError = True
End With
End Sub17.2 Conditional Formatting
Sub ApplyStatusColors()
Dim ws As Worksheet, rng As Range
Set ws = ThisWorkbook.Worksheets("RawData")
Set rng = ws.Range("C2:C5000")
rng.FormatConditions.Delete
With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""FAIL""")
.Interior.Color = RGB(255, 199, 206)
.Font.Color = RGB(156, 0, 6)
End With
With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""PASS""")
.Interior.Color = RGB(198, 239, 206)
.Font.Color = RGB(0, 97, 0)
End With
End Sub17.3 Sheet Create / Rename / Protect
Function SheetExists(ByVal sheetName As String, _
Optional ByVal wb As Workbook) As Boolean
Dim ws As Worksheet
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set ws = wb.Worksheets(sheetName)
On Error GoTo 0
SheetExists = Not ws Is Nothing
End Function
Sub CreateSummarySheetIfMissing()
Dim ws As Worksheet
If Not SheetExists("Summary", ThisWorkbook) Then
Set ws = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))
ws.Name = "Summary"
End If
End SubSub ProtectReportSheet()
ThisWorkbook.Worksheets("Report").Protect Password:="ChangeThisPassword", _
UserInterfaceOnly:=True, AllowFiltering:=True
End Sub
Sub UnprotectReportSheet()
ThisWorkbook.Worksheets("Report").Unprotect Password:="ChangeThisPassword"
End Sub17.4 Formula Result Value হিসেবে Freeze করা
Sub ConvertSelectedFormulasToValues()
If TypeName(Selection) <> "Range" Then Exit Sub
With Selection
.Value = .Value
End With
End Sub17.5 Outlook Classic-এ Email Draft তৈরি
Windows Desktop-এ Classic Outlook Installed ও Configured থাকলে VBA দিয়ে Email Draft তৈরি করা যায়। নিচের Code শুধু Draft Display করে; নিজে থেকে Send করে না। New Outlook-এ Classic COM Automation সমর্থন একইরকম নাও হতে পারে।
Sub CreateOutlookDraft()
Dim outlookApp As Object, mailItem As Object
On Error GoTo CleanFail
Set outlookApp = CreateObject("Outlook.Application")
Set mailItem = outlookApp.CreateItem(0)
With mailItem
.To = "recipient@example.com" ' নিজের অনুমোদিত Address দিন
.Subject = "Daily Quality Report"
.Body = "Hello," & vbCrLf & vbCrLf & _
"Please find the daily quality summary attached." & vbCrLf & _
"Regards"
.Display ' Draft দেখাবে; automatic send নয়
End With
Exit Sub
CleanFail:
MsgBox "Could not create Outlook draft: " & Err.Description, vbExclamation
End Sub17.6 External Workbook-এ Macro দিয়ে Report Save
Sub SaveReportCopy()
Dim targetFolder As String, targetFile As String
targetFolder = "C:\Reports\"
If Dir(targetFolder, vbDirectory) = "" Then MkDir targetFolder
targetFile = targetFolder & "Daily_Report_" & Format(Now, "yyyymmdd_hhnnss") & ".xlsm"
ThisWorkbook.SaveCopyAs targetFile
MsgBox "Copy saved: " & targetFile, vbInformation
End Sub17.7 Workbook Open হলে Macro চালান
এই Code Standard Module-এ নয়, ThisWorkbook Object-এর Code Window-তে Paste করবেন। Macro Security অনুমোদন না করলে Event Code Run হবে না।
Private Sub Workbook_Open()
On Error GoTo CleanFail
Application.StatusBar = "Refreshing workbook..."
ThisWorkbook.RefreshAll
ThisWorkbook.Worksheets("Dashboard").Activate
CleanExit:
Application.StatusBar = False
Exit Sub
CleanFail:
Application.StatusBar = False
MsgBox "Open automation failed: " & Err.Description, vbExclamation
Resume CleanExit
End Sub17.8 নির্দিষ্ট সময় পরে Macro Run — Application.OnTime
Excel Open থাকা অবস্থায় নির্দিষ্ট সময় পরে VBA Procedure চালাতে Application.OnTime ব্যবহার করা যায়। এটি Excel বন্ধ থাকলে Background Scheduler হিসেবে কাজ করে না। নিচের উদাহরণ ৫ মিনিট পরে Report Macro একবার চালায়।
Public nextRunTime As Date
Sub ScheduleReportInFiveMinutes()
nextRunTime = Now + TimeSerial(0, 5, 0)
Application.OnTime EarliestTime:=nextRunTime, _
Procedure:="RunScheduledReport", Schedule:=True
MsgBox "Report is scheduled for " & Format(nextRunTime, "hh:mm:ss")
End Sub
Sub RunScheduledReport()
BuildQualityReport
End Sub
Sub CancelScheduledReport()
On Error Resume Next
Application.OnTime EarliestTime:=nextRunTime, _
Procedure:="RunScheduledReport", Schedule:=False
On Error GoTo 0
End Subএই উদাহরণের জন্য BuildQualityReport Macro একই VBA Project-এ থাকতে হবে। Scheduled Time হওয়ার আগে Excel বন্ধ করলে Macro Run হবে না। বারবার Schedule করতে চাইলে Run হওয়ার পর পরবর্তী Time নতুন করে Schedule করতে হবে এবং Workbook Close-এর আগে Pending Schedule Cancel করার ব্যবস্থা রাখতে হবে।
18. VBA Event Automation — কোন Event কখন ব্যবহার করবেন?
| Event | কখন Run হয় | Use Case |
|---|---|---|
| Workbook_Open | Workbook Open হলে | Dashboard Refresh, Welcome Message |
| Workbook_BeforeClose | Workbook বন্ধের আগে | Final Save Check, Exit Warning |
| Workbook_BeforeSave | Save-এর আগে | Required Field Validation |
| Worksheet_Change | User/External Link Cell Value বদলালে | Status Update, Timestamp |
| Worksheet_SelectionChange | Selection বদলালে | Selected Row Highlight/Helper |
| Worksheet_Activate | Sheet Activate হলে | Refresh বা Navigation Setup |
| Worksheet_Calculate | Sheet Recalculate হলে | Formula Result পর্যবেক্ষণ |
| Workbook_SheetChange | Workbook-এর যেকোনো Sheet-এ Cell Change হলে | Central Change Log |
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("আপনি কি Workbook বন্ধ করতে চান?", _
vbQuestion + vbYesNo, "Confirm Exit") = vbNo Then
Cancel = True
End If
End SubPrivate Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim logWs As Worksheet, nextRow As Long
On Error GoTo CleanFail
If Sh.Name = "ChangeLog" Then Exit Sub
If Target.CountLarge > 1 Then Exit Sub ' bulk paste ignore করা হচ্ছে
Set logWs = ThisWorkbook.Worksheets("ChangeLog")
Application.EnableEvents = False
nextRow = logWs.Cells(logWs.Rows.Count, "A").End(xlUp).Row + 1
logWs.Cells(nextRow, "A").Value = Now
logWs.Cells(nextRow, "B").Value = Sh.Name
logWs.Cells(nextRow, "C").Value = Target.Address(False, False)
logWs.Cells(nextRow, "D").Value = Target.Value
CleanExit:
Application.EnableEvents = True
Exit Sub
CleanFail:
Application.EnableEvents = True
MsgBox "Change log error: " & Err.Description, vbExclamation
End Subএই Sample নতুন Value Log করে; পুরনো Value Log করতে আগে Change হওয়ার আগের Value Capture করার আলাদা Design দরকার। Sensitive Data, Password বা Personal Information Change Log-এ অপ্রয়োজনে রাখবেন না। Bulk Paste হলে Sample-টি ইচ্ছাকৃতভাবে Log করে না।
19. Error Handling — Macro যেন মাঝপথে ভেঙে না পড়ে
File Missing, Sheet Name ভুল, Protected Sheet, Empty Range, Invalid Data বা External Application না থাকলে Macro Error দিতে পারে। Professional Macro-তে Error Handler, Cleanup এবং Application Setting Restore থাকা জরুরি।
Sub SafeMacroTemplate()
Dim oldScreen As Boolean, oldEvents As Boolean
Dim oldCalc As XlCalculation
oldScreen = Application.ScreenUpdating
oldEvents = Application.EnableEvents
oldCalc = Application.Calculation
On Error GoTo CleanFail
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
' ===== YOUR AUTOMATION CODE HERE =====
ThisWorkbook.Worksheets("Report").Range("A1").Value = "Updated"
CleanExit:
Application.ScreenUpdating = oldScreen
Application.EnableEvents = oldEvents
Application.Calculation = oldCalc
Exit Sub
CleanFail:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
Resume CleanExit
End Subসবচেয়ে বড় শিক্ষা: ScreenUpdating, EnableEvents, Calculation বদলালে Macro শেষ/Fail—দুই অবস্থাতেই আগের Setting Restore করতে হবে।
20. Macro Speed & Performance — Professional Tips and Tricks
20.1 ScreenUpdating, EnableEvents, Calculation
Sub FastProcessingTemplate()
Dim oldScreen As Boolean, oldEvents As Boolean
Dim oldCalc As XlCalculation
Dim ws As Worksheet, lastRow As Long
oldScreen = Application.ScreenUpdating
oldEvents = Application.EnableEvents
oldCalc = Application.Calculation
On Error GoTo CleanFail
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
If lastRow >= 2 Then
ws.Range("D2:D" & lastRow).Value = "Processed"
End If
CleanExit:
Application.ScreenUpdating = oldScreen
Application.EnableEvents = oldEvents
Application.Calculation = oldCalc
Exit Sub
CleanFail:
MsgBox Err.Description, vbCritical
Resume CleanExit
End Sub20.2 Speed Tips Checklist
Select/Activateছাড়া সরাসরি Worksheet/Range Reference ব্যবহার করুন।- প্রতিটি Cell আলাদা Read/Write না করে বড় Range একবারে Process করুন।
- বড় Data-তে Variant Array ব্যবহার করুন।
- অপ্রয়োজনীয় Formula Recalculation বন্ধ করে শেষে Restore করুন।
- একই Workbook বারবার Open/Close করবেন না।
UsedRangeসবসময় প্রকৃত Last Row বোঝায় না; Key Column-এর End(xlUp) ব্যবহার করুন।- VBA Loop-এ হাজার হাজার বার Copy/Paste-এর বদলে Value Array Transfer বিবেচনা করুন।
- অপ্রয়োজনীয় DoEvents ব্যবহার করবেন না; প্রয়োজন হলে দীর্ঘ Loop-এ সীমিত ব্যবধানে দিন।
- Workbook Link অনেক হলে Refresh Time ও Link Breakage পর্যবেক্ষণ করুন।
- Error Handling ছাড়া Events/Calculation বন্ধ করে রেখে দেবেন না।
Application.Calculate বা Target Range Calculate করুন।21. Macro Security — নিরাপদে Macro ব্যবহার করুন
VBA Macro একটি Workbook-এর ভিতরেই সীমাবদ্ধ নয়—Code-এর ক্ষমতা দিয়ে Local File, Folder, Application ও অন্যান্য Resource-এ কাজ করা সম্ভব। তাই অজানা Email Attachment বা Internet থেকে পাওয়া Macro-enabled File অন্ধভাবে Enable করবেন না।
- শুধু নিজের তৈরি বা বিশ্বস্ত Source-এর Macro Run করুন।
- Macro Settings-এ “Disable all macros with notification” সাধারণত নিরাপদ ভারসাম্য দেয়; সব Macro globally Enable করা সুপারিশযোগ্য নয়।
- Trusted Location কেবল নিয়ন্ত্রিত ও প্রয়োজনীয় Folder-এর জন্য ব্যবহার করুন।
- প্রাতিষ্ঠানিক ব্যবহারে Digital Signature ও Trusted Publisher Policy বিবেচনা করুন।
- Internet থেকে Download করা Office File-এ Macro Block হতে পারে; এটি Security Feature—অজানা File Unblock করবেন না।
- প্রথমবার Macro চালানোর আগে File-এর Backup/Copy রাখুন।
22. Debugging — Code Error খুঁজে বের করার কৌশল
| Tool / Command | কাজ | কীভাবে ব্যবহার করবেন |
|---|---|---|
| F8 Step Into | এক লাইন করে Code চালানো | VBE-তে Macro-র ভিতরে F8 চাপুন |
| F5 Run | Macro Run | Cursor Procedure-এর ভিতরে রেখে F5 |
| Breakpoints (F9) | নির্দিষ্ট লাইনে থামানো | Line Select করে F9 |
| Immediate Window (Ctrl+G) | Quick Test ও Debug Print | ? Range("A1").Value |
| Locals Window | বর্তমান Variable-এর Value দেখা | View → Locals Window |
| Watch Window | নির্দিষ্ট Variable/Expression Track | Debug → Add Watch |
| Debug.Print | Immediate Window-তে Value Print | Debug.Print lastRow |
| On Error | Runtime Error Handle | CleanFail Handler |
Sub DebugExample()
Dim ws As Worksheet, lastRow As Long
Set ws = ThisWorkbook.Worksheets("RawData")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Debug.Print "Sheet: " & ws.Name
Debug.Print "Last Row: " & lastRow
Debug.Print "A2 Value: " & ws.Range("A2").Value
End SubCommon Error Messages
| Error | সম্ভাব্য কারণ | সমাধান |
|---|---|---|
| Subscript out of range (9) | Sheet/Workbook Name মেলেনি | Sheet Tab-এর সঠিক নাম Verify করুন |
| Object variable not set (91) | Set দিয়ে Object Assign করা হয়নি | Workbook/Worksheet/Range Object Set করুন |
| Type mismatch (13) | ভুল Data Type বা Error Value | CStr/CDbl/IsError/IsNumeric দিয়ে Validate করুন |
| Application-defined or object-defined error (1004) | Invalid Range/Protection/Bad Address | Range Address ও Sheet Protection Check করুন |
| Permission denied (70) | File/Folder Access নেই বা File Locked | Permission/Path/Lock Check করুন |
| File not found | Path বা Filename ভুল | Dir দিয়ে File Exists Check করুন |
| Macro not listed | Wrong Module, Private Sub বা Macro Disabled | Public Sub Standard Module-এ রাখুন; Security Check করুন |
23. Excel Macro & VBA Shortcut Keys
| Shortcut | কাজ |
|---|---|
| Alt + F11 | Visual Basic Editor Open/Close |
| Alt + F8 | Macro Dialog Open |
| F5 | VBE থেকে Procedure Run |
| F8 | Step Into — Line by Line |
| F9 | Breakpoint Toggle |
| Ctrl + G (VBE) | Immediate Window |
| Ctrl + R (VBE) | Project Explorer |
| F2 (VBE) | Object Browser |
| F1 (VBE) | Help |
| Ctrl + S | Workbook/Project Save |
| Ctrl + Break | Running Macro Interrupt করার চেষ্টা |
| Alt + F11 → Insert → Module | New Standard Module |
| Developer → Record Macro | Macro Recording Start |
| Developer → Stop Recording | Recording Stop |
| Ctrl + T | Excel Table Create (Worksheet) |
Shortcut Key Application/Keyboard Layout অনুযায়ী বদলাতে পারে। VBE-তে F5/F8/F9 ব্যবহার সবচেয়ে বেশি কাজে লাগবে।
24. Complete Practical Project — Repair & Quality Testing Automation
এবার শেখা বিষয়গুলি একসঙ্গে ব্যবহার করি। ধরুন আপনার Electronics Repair/Testing Department-এর জন্য Raw Data আছে। প্রতিটি Row একটি Product/Work Order Record। Macro এক Click-এ Serial, Status, KPI Summary, Formatting ও PDF Report তৈরি করবে।
24.1 Workbook Structure
| Sheet Name | কাজ | প্রস্তাবিত Columns |
|---|---|---|
| RawData | Original Entry / Master Table | Date, WorkOrder, ProductID, Product, TestResult, RepairMinutes, Technician |
| Summary | KPI Summary | Total, Pass, Fail, Pass Rate, Average Repair Time |
| Dashboard | Management View | KPI Cards, Monthly Trend, Fail Cause Chart |
| FailRecords | Failed Items | RawData থেকে Fail Rows Copy |
| ChangeLog | Change Audit | Timestamp, Sheet, Cell, New Value |
24.2 Example Raw Data
| Date | Work Order | Product ID | Product | Test Result | Repair Min | Technician |
|---|---|---|---|---|---|---|
| 01-Nov-2026 | WO1001 | P101 | Battery | Pass | 12 | Operator A |
| 01-Nov-2026 | WO1002 | P102 | Speaker | Fail | 28 | Operator B |
| 02-Nov-2026 | WO1003 | P103 | Display | Pass | 16 | Operator A |
| 02-Nov-2026 | WO1004 | P104 | Charging Port | Fail | 35 | Operator C |
| 03-Nov-2026 | WO1005 | P105 | Button | Pass | 10 | Operator B |
24.3 One-Click Master Report Macro
Option Explicit
Sub BuildQualityReport()
Dim wb As Workbook
Dim raw As Worksheet, summary As Worksheet, fails As Worksheet
Dim lastRow As Long, r As Long, nextRow As Long
Dim totalCount As Long, passCount As Long, failCount As Long
Dim totalMinutes As Double, avgMinutes As Double, passRate As Double
Dim oldScreen As Boolean, oldEvents As Boolean
Dim oldCalc As XlCalculation
Dim pdfPath As String
Set wb = ThisWorkbook
Set raw = wb.Worksheets("RawData")
Set summary = wb.Worksheets("Summary")
Set fails = wb.Worksheets("FailRecords")
oldScreen = Application.ScreenUpdating
oldEvents = Application.EnableEvents
oldCalc = Application.Calculation
On Error GoTo CleanFail
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
lastRow = raw.Cells(raw.Rows.Count, "B").End(xlUp).Row
If lastRow < 2 Then Err.Raise vbObjectError + 100, , "RawData has no records."
' Prepare FailRecords header
fails.Cells.Clear
raw.Range("A1:G1").Copy Destination:=fails.Range("A1")
nextRow = 2
totalCount = 0: passCount = 0: failCount = 0: totalMinutes = 0
For r = 2 To lastRow
If Len(Trim$(CStr(raw.Cells(r, "B").Value))) > 0 Then
totalCount = totalCount + 1
Select Case UCase$(Trim$(CStr(raw.Cells(r, "E").Value)))
Case "PASS"
passCount = passCount + 1
Case "FAIL"
failCount = failCount + 1
raw.Range("A" & r & ":G" & r).Copy fails.Cells(nextRow, 1)
nextRow = nextRow + 1
End Select
If IsNumeric(raw.Cells(r, "F").Value) Then
totalMinutes = totalMinutes + CDbl(raw.Cells(r, "F").Value)
End If
End If
Next r
If totalCount > 0 Then
avgMinutes = totalMinutes / totalCount
passRate = passCount / totalCount
End If
' Build KPI summary
summary.Cells.Clear
summary.Range("A1").Value = "KPI"
summary.Range("B1").Value = "Value"
summary.Range("A2").Value = "Total Records": summary.Range("B2").Value = totalCount
summary.Range("A3").Value = "Pass Count": summary.Range("B3").Value = passCount
summary.Range("A4").Value = "Fail Count": summary.Range("B4").Value = failCount
summary.Range("A5").Value = "Pass Rate": summary.Range("B5").Value = passRate
summary.Range("A6").Value = "Average Repair Minutes": summary.Range("B6").Value = avgMinutes
summary.Range("B5").NumberFormat = "0.0%"
summary.Range("B6").NumberFormat = "0.0"
' Format sheets
FormatOneSheet raw
FormatOneSheet summary
FormatOneSheet fails
If Len(wb.Path) > 0 Then
pdfPath = wb.Path & "\Quality_Report_" & Format(Now, "yyyymmdd_hhnnss") & ".pdf"
summary.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, _
Quality:=xlQualityStandard, IgnorePrintAreas:=False
End If
MsgBox "Quality report completed." & vbCrLf & _
"Total: " & totalCount & vbCrLf & _
"Pass: " & passCount & vbCrLf & _
"Fail: " & failCount, vbInformation
CleanExit:
Application.ScreenUpdating = oldScreen
Application.EnableEvents = oldEvents
Application.Calculation = oldCalc
Exit Sub
CleanFail:
MsgBox "Report error: " & Err.Description, vbCritical
Resume CleanExit
End Sub
Private Sub FormatOneSheet(ByVal ws As Worksheet)
Dim lastCol As Long, lastRow As Long
If Application.WorksheetFunction.CountA(ws.Cells) = 0 Then Exit Sub
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
With ws.Range(ws.Cells(1, 1), ws.Cells(1, lastCol))
.Font.Bold = True
.Font.Color = vbWhite
.Interior.Color = RGB(31, 78, 121)
End With
ws.Columns(1).Resize(, lastCol).AutoFit
End Sub24.4 Project-কে আরও Professional করুন
- RawData-কে
tblRepairনামে Excel Table করুন। - WorkOrder বা ProductID-কে Unique Key হিসেবে Validate করুন।
- Dropdown দিয়ে TestResult-এর Value নিয়ন্ত্রণ করুন।
- Technician, Product, Month, Shift অনুযায়ী PivotTable তৈরি করুন।
- Dashboard-এ Pass Rate, Fail Count, Average Repair Time, Top Defect Cause এবং Monthly Trend দেখান।
- Slicer দিয়ে Month, Product ও Technician Filter করুন।
- ChangeLog-এ কে কখন কোন Data বদলেছে তা Audit করুন; User Identity নিশ্চিত করতে Windows/Office Environment-এর উপযুক্ত পরিচয় পদ্ধতি লাগবে।
- PDF/Email Share করার আগে Confidential Information ও Recipient Verify করুন।
25. Macro দিয়ে কী কী করা যায় — এবং সীমাবদ্ধতা কী?
যে কাজগুলি VBA দিয়ে Automate করা যায়
যে সীমাবদ্ধতাগুলি বুঝতে হবে
- Excel বন্ধ থাকলে Workbook-এর ভিতরের সাধারণ VBA Event নিজে থেকে চলবে না। Scheduled unattended workflow-এর জন্য Task Scheduler/Power Automate/অন্যান্য অনুমোদিত ব্যবস্থা দরকার।
- Excel for the Web VBA Macro Execute করে না।
- Macro Run করার আগে Workbook Security ও Trust Policy অনুমোদন দরকার হতে পারে।
- একটি Macro সবসময় Undo করা যায় না। Ctrl+Z দিয়ে VBA Action ফিরিয়ে নেওয়া যাবে ধরে নেবেন না।
- অনেক External Workbook Link brittle/slow হতে পারে; Power Query/Database ব্যবহার উপযোগী হতে পারে।
- Windows-specific API, ActiveX ও COM Automation Mac-এ সমর্থিত নাও হতে পারে।
- Macro দিয়ে ভুল Logic চালালে ভুল Data overwrite, delete বা export হতে পারে—Backup, Validation ও Test বাধ্যতামূলক।
26. Excel Macro & VBA — 30-Day Practical Learning Roadmap
| সময় | কী শিখবেন | Practical Output |
|---|---|---|
| Day 1–3 | Developer Tab, Macro Recorder, .xlsm, Relative Reference | একটি Report Formatting Macro |
| Day 4–7 | VBE, Sub, Variable, If, Loop, Select Case | Pass/Fail Status Automation |
| Day 8–10 | Workbook, Worksheet, Range, Cells, LastRow | Dynamic Range Processing |
| Day 11–14 | Text Cleaning, Duplicate, Sort, Filter, Formula | One-Click Data Cleaning Tool |
| Day 15–18 | Folder Picker, Dir, Workbooks.Open, Consolidation | Multiple File Master Data Builder |
| Day 19–21 | PDF Export, Backup, Print, Chart, Pivot Refresh | Automated Weekly Report |
| Day 22–24 | Worksheet/Workbook Events, UserForm, Buttons | Data Entry Form + Timestamp |
| Day 25–27 | Error Handling, Debugging, Performance, Security | Stable Macro with Logging |
| Day 28–30 | Complete Repair/Quality Dashboard Project | Interview-ready Portfolio Project |
Interview-এ কীভাবে Project Explain করবেন?
“আমি একটি Excel VBA-based Quality Reporting Tool তৈরি করেছি। Raw Data থেকে Pass/Fail Summary, Failed Record Extraction, KPI Calculation, Report Formatting এবং PDF Export এক Button-এ হয়। Macro-তে Dynamic Last Row, Error Handling, Event Control এবং Application Settings Restore ব্যবহার করেছি। Data Source ও Output Structure Standardized রেখেছি।”
27. Frequently Asked Questions — Excel Macro FAQ
Macro আর VBA কি একই জিনিস?
Macro হলো Repeatable Task/Automation; VBA হলো সেই Macro তৈরি ও Customize করার Programming Language।
Macro Recorder কি সব কাজ Record করে?
না। Recorder অনেক Excel UI Action Record করে, কিন্তু Complex Decision, Robust File Logic, Advanced Error Handling বা সব User Interaction Record করতে পারে না। পরে VBA Edit করতে হয়।
Excel .xlsx-এ Macro Save হবে?
না। VBA Code সংরক্ষণ করতে .xlsm বা উপযুক্ত Macro-enabled Format যেমন .xlsb ব্যবহার করুন।
Excel Online-এ Macro চলে?
না। Excel for the Web VBA Macro Create, Run বা Edit করতে পারে না। Desktop Excel প্রয়োজন।
একটি Button Click-এ 10,000 Row Process করা যাবে?
হ্যাঁ, Data Layout ও Machine Resources উপযুক্ত হলে সম্ভব। বড় Data-তে Array, Table, Power Query ও Performance Techniques ব্যবহার করুন।
একটি Workbook থেকে অন্য Workbook-এ Data Auto Update হবে?
VBA Macro চালিয়ে নির্দিষ্ট সময়ে Data Copy করা যায়; এটি নিজে নিজে Live Link নয়। External Link, Power Query Refresh বা Event/Workflow Design আলাদা বিষয়।
Macro দিয়ে PDF তৈরি করা যায়?
হ্যাঁ। Worksheet/Workbook-এর Print Area ও Page Setup ঠিক করে ExportAsFixedFormat ব্যবহার করা যায়।
Macro কি নিজে থেকে Email Send করতে পারে?
নির্দিষ্ট Desktop Outlook/Environment-এ Automation সম্ভব, কিন্তু Security ও Compatibility গুরুত্বপূর্ণ। প্রথমে Draft তৈরি করে Review করা নিরাপদ।
Macro কি Undo করা যায়?
সাধারণত VBA Macro Action Excel Undo History-তে থাকে না। তাই Backup/Copy নিয়ে Run করুন।
Macro চালু হচ্ছে না কেন?
File Type, Macro Security, Downloaded File Block, Wrong Module, Compile Error, Missing Reference বা Workbook Name পরীক্ষা করুন।
VBA না Power Query—কোনটি শিখব?
দুটিই শিখুন। Data Import/Transform/Combine-এ Power Query; Desktop Workbook Interaction, Buttons, Events ও Complex Workflow-এ VBA।
Macro কি Virus হতে পারে?
Malicious Macro Code ক্ষতি করতে পারে। অজানা File Enable করবেন না; Trusted Source, Security Settings ও Digital Signature Policy অনুসরণ করুন।
28. Microsoft Official References & Further Learning
Macro শেখার সময় Microsoft Support ও Microsoft Learn-এর Official Documentation ব্যবহার করুন। Excel Update ও Security Policy বদলাতে পারে; প্রয়োজন হলে Official Page থেকে বর্তমান নির্দেশনা যাচাই করুন।
- Quick start: Create a macro — Macro Recorder ও প্রথম Macro।
- Automate tasks with the Macro Recorder — Record, Run ও Recorder Workflow।
- Save a macro — .xlsm ও Personal Macro Workbook।
- Run a macro in Excel — Macro Run এবং Workbook_Open Event।
- Change macro security settings in Excel — Trust Center ও Macro Security।
- Macros from the internet are blocked by default in Office — Internet Macro Security।
- Excel performance: Tips for optimizing performance obstructions — VBA Performance Tips।
- Worksheet.Change Event — Cell Change Event Reference।
- Differences between Office Scripts and VBA macros — VBA বনাম Office Scripts।
- Office Scripts in Excel — Cloud/Script Automation।
- Work with VBA macros in Excel for the web — Excel Web Compatibility।