<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[QP School - Excel VBA Tutorials]]></title>
		<link>https://qomplainerzschool.lima-city.de/</link>
		<description><![CDATA[QP School - https://qomplainerzschool.lima-city.de]]></description>
		<pubDate>Fri, 01 May 2026 13:14:42 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Format cells in a range with bold font and yellow background color]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5272</link>
			<pubDate>Thu, 27 Jul 2023 13:26:06 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5272</guid>
			<description><![CDATA[Example:<br />
<br />
Sub FormatCellsInRange()<br />
    Dim ws As Worksheet<br />
    Dim formatRange As Range<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Set the range of cells to be formatted (adjust the range as per your data)<br />
    Set formatRange = ws.Range("A1:B5")<br />
<br />
    'Apply formatting to the range<br />
    With formatRange<br />
        .Font.Bold = True<br />
        .Interior.Color = RGB(255, 255, 0) 'Yellow color<br />
    End With<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named FormatCellsInRange.<br />
It declares variables for the worksheet (ws) and the range of cells to be formatted (formatRange).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
Set formatRange = ws.Range("A1:B5") sets the range A1:B5 to be formatted. <br />
Adjust the range as per your data.<br />
The With block is used to apply formatting to the formatRange.<br />
.Font.Bold = True makes the font bold for all cells in the range.<br />
.Interior.Color = RGB(255, 255, 0) sets the background color of all cells in the range to yellow using the RGB value (255, 255, 0).]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub FormatCellsInRange()<br />
    Dim ws As Worksheet<br />
    Dim formatRange As Range<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Set the range of cells to be formatted (adjust the range as per your data)<br />
    Set formatRange = ws.Range("A1:B5")<br />
<br />
    'Apply formatting to the range<br />
    With formatRange<br />
        .Font.Bold = True<br />
        .Interior.Color = RGB(255, 255, 0) 'Yellow color<br />
    End With<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named FormatCellsInRange.<br />
It declares variables for the worksheet (ws) and the range of cells to be formatted (formatRange).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
Set formatRange = ws.Range("A1:B5") sets the range A1:B5 to be formatted. <br />
Adjust the range as per your data.<br />
The With block is used to apply formatting to the formatRange.<br />
.Font.Bold = True makes the font bold for all cells in the range.<br />
.Interior.Color = RGB(255, 255, 0) sets the background color of all cells in the range to yellow using the RGB value (255, 255, 0).]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Copy data to another worksheet]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5271</link>
			<pubDate>Thu, 27 Jul 2023 13:24:59 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5271</guid>
			<description><![CDATA[Example:<br />
<br />
Sub CopyDataToAnotherSheet()<br />
    Dim sourceWs As Worksheet<br />
    Dim targetWs As Worksheet<br />
    Dim lastRowSource As Long<br />
    Dim lastRowTarget As Long<br />
<br />
    'Set the source worksheet where the data is located<br />
    Set sourceWs = ThisWorkbook.Sheets("SourceSheet")<br />
<br />
    'Set the target worksheet where the data will be copied<br />
    Set targetWs = ThisWorkbook.Sheets("TargetSheet")<br />
<br />
    'Find the last row with data in the source worksheet<br />
    lastRowSource = sourceWs.Cells(sourceWs.Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Find the last row with data in the target worksheet<br />
    lastRowTarget = targetWs.Cells(targetWs.Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Copy the data from the source worksheet to the target worksheet<br />
    sourceWs.Range("A1:A" &amp; lastRowSource).Copy targetWs.Range("A" &amp; lastRowTarget + 1)<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CopyDataToAnotherSheet.<br />
It declares variables for the source worksheet (sourceWs), the target worksheet (targetWs), and the last row with data in each worksheet (lastRowSource and lastRowTarget).<br />
Set sourceWs = ThisWorkbook.Sheets("SourceSheet") specifies the source worksheet ("SourceSheet") where the data is located.<br />
Set targetWs = ThisWorkbook.Sheets("TargetSheet") specifies the target worksheet ("TargetSheet") where the data will be copied.<br />
The lastRowSource variable is determined using sourceWs.Cells(sourceWs.Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A of the source worksheet.<br />
The lastRowTarget variable is determined using targetWs.Cells(targetWs.Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A of the target worksheet.<br />
The data from column A of the source worksheet (from A1 to the last row with data) is copied to the target worksheet starting from the next empty row in column A.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub CopyDataToAnotherSheet()<br />
    Dim sourceWs As Worksheet<br />
    Dim targetWs As Worksheet<br />
    Dim lastRowSource As Long<br />
    Dim lastRowTarget As Long<br />
<br />
    'Set the source worksheet where the data is located<br />
    Set sourceWs = ThisWorkbook.Sheets("SourceSheet")<br />
<br />
    'Set the target worksheet where the data will be copied<br />
    Set targetWs = ThisWorkbook.Sheets("TargetSheet")<br />
<br />
    'Find the last row with data in the source worksheet<br />
    lastRowSource = sourceWs.Cells(sourceWs.Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Find the last row with data in the target worksheet<br />
    lastRowTarget = targetWs.Cells(targetWs.Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Copy the data from the source worksheet to the target worksheet<br />
    sourceWs.Range("A1:A" &amp; lastRowSource).Copy targetWs.Range("A" &amp; lastRowTarget + 1)<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CopyDataToAnotherSheet.<br />
It declares variables for the source worksheet (sourceWs), the target worksheet (targetWs), and the last row with data in each worksheet (lastRowSource and lastRowTarget).<br />
Set sourceWs = ThisWorkbook.Sheets("SourceSheet") specifies the source worksheet ("SourceSheet") where the data is located.<br />
Set targetWs = ThisWorkbook.Sheets("TargetSheet") specifies the target worksheet ("TargetSheet") where the data will be copied.<br />
The lastRowSource variable is determined using sourceWs.Cells(sourceWs.Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A of the source worksheet.<br />
The lastRowTarget variable is determined using targetWs.Cells(targetWs.Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A of the target worksheet.<br />
The data from column A of the source worksheet (from A1 to the last row with data) is copied to the target worksheet starting from the next empty row in column A.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Autofill a series of numbers in a column]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5270</link>
			<pubDate>Thu, 27 Jul 2023 13:23:58 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5270</guid>
			<description><![CDATA[Example:<br />
<br />
Sub AutofillSeries()<br />
    Dim ws As Worksheet<br />
    Dim startValue As Integer<br />
    Dim endValue As Integer<br />
<br />
    'Set the worksheet where the series will be created<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Specify the start and end values for the series<br />
    startValue = 1<br />
    endValue = 10<br />
<br />
    'Enter the start value in the first cell of the series (A1)<br />
    ws.Range("A1").Value = startValue<br />
<br />
    'Autofill the series from the second cell (A2) to the end value (A10)<br />
    ws.Range("A1").AutoFill Destination:=ws.Range("A1:A10"), Type:=xlFillSeries<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named AutofillSeries.<br />
It declares variables for the worksheet (ws), the start value of the series (startValue), and the end value of the series (endValue).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the series will be created.<br />
startValue = 1 and endValue = 10 set the start and end values for the series.<br />
The start value (1 in this example) is entered in cell A1 using ws.Range("A1").Value = startValue.<br />
The ws.Range("A1").AutoFill method is used to autofill the series from cell A2 to cell A10. <br />
Destination:=ws.Range("A1:A10") specifies the destination range for autofilling, and Type:=xlFillSeries indicates that it should be filled as a series.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub AutofillSeries()<br />
    Dim ws As Worksheet<br />
    Dim startValue As Integer<br />
    Dim endValue As Integer<br />
<br />
    'Set the worksheet where the series will be created<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Specify the start and end values for the series<br />
    startValue = 1<br />
    endValue = 10<br />
<br />
    'Enter the start value in the first cell of the series (A1)<br />
    ws.Range("A1").Value = startValue<br />
<br />
    'Autofill the series from the second cell (A2) to the end value (A10)<br />
    ws.Range("A1").AutoFill Destination:=ws.Range("A1:A10"), Type:=xlFillSeries<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named AutofillSeries.<br />
It declares variables for the worksheet (ws), the start value of the series (startValue), and the end value of the series (endValue).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the series will be created.<br />
startValue = 1 and endValue = 10 set the start and end values for the series.<br />
The start value (1 in this example) is entered in cell A1 using ws.Range("A1").Value = startValue.<br />
The ws.Range("A1").AutoFill method is used to autofill the series from cell A2 to cell A10. <br />
Destination:=ws.Range("A1:A10") specifies the destination range for autofilling, and Type:=xlFillSeries indicates that it should be filled as a series.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Loop through columns and clear contents]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5269</link>
			<pubDate>Thu, 27 Jul 2023 13:21:28 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5269</guid>
			<description><![CDATA[Example:<br />
<br />
Sub ClearContentsInColumns()<br />
    Dim ws As Worksheet<br />
    Dim lastColumn As Long<br />
    Dim col As Long<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Find the last column with data in the worksheet<br />
    lastColumn = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column<br />
<br />
    'Loop through each column and clear the contents<br />
    For col = 1 To lastColumn<br />
        ws.Columns(col).ClearContents<br />
    Next col<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named ClearContentsInColumns.<br />
It declares variables for the worksheet (ws), the last column with data (lastColumn), and a loop counter (col).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
The lastColumn variable is determined using ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column, which finds the last column with data in the worksheet.<br />
The For loop iterates through each column from 1 to lastColumn.<br />
ws.Columns(col).ClearContents clears the contents of each cell in the current column (col) of the worksheet.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub ClearContentsInColumns()<br />
    Dim ws As Worksheet<br />
    Dim lastColumn As Long<br />
    Dim col As Long<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Find the last column with data in the worksheet<br />
    lastColumn = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column<br />
<br />
    'Loop through each column and clear the contents<br />
    For col = 1 To lastColumn<br />
        ws.Columns(col).ClearContents<br />
    Next col<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named ClearContentsInColumns.<br />
It declares variables for the worksheet (ws), the last column with data (lastColumn), and a loop counter (col).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
The lastColumn variable is determined using ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column, which finds the last column with data in the worksheet.<br />
The For loop iterates through each column from 1 to lastColumn.<br />
ws.Columns(col).ClearContents clears the contents of each cell in the current column (col) of the worksheet.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Sum values based on criteria]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5268</link>
			<pubDate>Thu, 27 Jul 2023 13:20:19 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5268</guid>
			<description><![CDATA[Example:<br />
<br />
Sub SumValuesBasedOnCriteria()<br />
    Dim ws As Worksheet<br />
    Dim lastRow As Long<br />
    Dim i As Long<br />
    Dim sumResult As Double<br />
    Dim targetCriteria As String<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Find the last row with data in column A<br />
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Specify the target criterion in column A<br />
    targetCriteria = "Category1"<br />
<br />
    sumResult = 0 'Initialize the sum<br />
<br />
    'Loop through each row and calculate the sum of values in column B<br />
    For i = 1 To lastRow<br />
        If ws.Cells(i, "A").Value = targetCriteria Then<br />
            sumResult = sumResult + ws.Cells(i, "B").Value<br />
        End If<br />
    Next i<br />
<br />
    MsgBox "Sum of values for " &amp; targetCriteria &amp; ": " &amp; sumResult<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named SumValuesBasedOnCriteria.<br />
It declares variables for the worksheet (ws), the last row with data (lastRow), a loop counter (i), the sum result (sumResult), and the target criterion (targetCriteria) to calculate the sum for.<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
The lastRow variable is determined using ws.Cells(ws.Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A.<br />
targetCriteria = "Category1" specifies the criterion (Category1) for which the sum will be calculated.<br />
The For loop iterates through each row from 1 to lastRow.<br />
The If statement checks if the value in column A (ws.Cells(i, "A").Value) matches the targetCriteria. <br />
If it does, the value in column B (ws.Cells(i, "B").Value) is added to the sumResult.<br />
Finally, a message box displays the sum of values for the specified criterion.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub SumValuesBasedOnCriteria()<br />
    Dim ws As Worksheet<br />
    Dim lastRow As Long<br />
    Dim i As Long<br />
    Dim sumResult As Double<br />
    Dim targetCriteria As String<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Find the last row with data in column A<br />
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Specify the target criterion in column A<br />
    targetCriteria = "Category1"<br />
<br />
    sumResult = 0 'Initialize the sum<br />
<br />
    'Loop through each row and calculate the sum of values in column B<br />
    For i = 1 To lastRow<br />
        If ws.Cells(i, "A").Value = targetCriteria Then<br />
            sumResult = sumResult + ws.Cells(i, "B").Value<br />
        End If<br />
    Next i<br />
<br />
    MsgBox "Sum of values for " &amp; targetCriteria &amp; ": " &amp; sumResult<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named SumValuesBasedOnCriteria.<br />
It declares variables for the worksheet (ws), the last row with data (lastRow), a loop counter (i), the sum result (sumResult), and the target criterion (targetCriteria) to calculate the sum for.<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
The lastRow variable is determined using ws.Cells(ws.Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A.<br />
targetCriteria = "Category1" specifies the criterion (Category1) for which the sum will be calculated.<br />
The For loop iterates through each row from 1 to lastRow.<br />
The If statement checks if the value in column A (ws.Cells(i, "A").Value) matches the targetCriteria. <br />
If it does, the value in column B (ws.Cells(i, "B").Value) is added to the sumResult.<br />
Finally, a message box displays the sum of values for the specified criterion.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Create a hyperlink with VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5267</link>
			<pubDate>Thu, 27 Jul 2023 13:10:22 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5267</guid>
			<description><![CDATA[Example:<br />
<br />
Sub CreateHyperlink()<br />
    Dim ws As Worksheet<br />
<br />
    'Set the worksheet where the hyperlink will be created<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Create a hyperlink in cell A1<br />
    ws.Hyperlinks.Add _<br />
        Anchor:=ws.Range("A1"), _<br />
        Address:="https://www.example.com", _<br />
        TextToDisplay:="Visit Example Website"<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CreateHyperlink.<br />
It declares a variable for the worksheet (ws) where the hyperlink will be created.<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the hyperlink will be added.<br />
The ws.Hyperlinks.Add method is used to create a hyperlink.<br />
Anchor:=ws.Range("A1") sets cell A1 as the anchor for the hyperlink (where the link will be displayed).<br />
Address:="https://www.example.com" specifies the URL or address to which the hyperlink points.<br />
TextToDisplay:="Visit Example Website" sets the text that will be displayed for the hyperlink in cell A1.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub CreateHyperlink()<br />
    Dim ws As Worksheet<br />
<br />
    'Set the worksheet where the hyperlink will be created<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Create a hyperlink in cell A1<br />
    ws.Hyperlinks.Add _<br />
        Anchor:=ws.Range("A1"), _<br />
        Address:="https://www.example.com", _<br />
        TextToDisplay:="Visit Example Website"<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CreateHyperlink.<br />
It declares a variable for the worksheet (ws) where the hyperlink will be created.<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the hyperlink will be added.<br />
The ws.Hyperlinks.Add method is used to create a hyperlink.<br />
Anchor:=ws.Range("A1") sets cell A1 as the anchor for the hyperlink (where the link will be displayed).<br />
Address:="https://www.example.com" specifies the URL or address to which the hyperlink points.<br />
TextToDisplay:="Visit Example Website" sets the text that will be displayed for the hyperlink in cell A1.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Split text in cells with VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5266</link>
			<pubDate>Thu, 27 Jul 2023 13:09:33 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5266</guid>
			<description><![CDATA[Example:<br />
<br />
Sub SplitTextInCells()<br />
    Dim sourceRange As Range<br />
    Dim cell As Range<br />
    Dim parts As Variant<br />
<br />
    'Set the range where the text is located (assuming data starts from A1)<br />
    Set sourceRange = Range("A1:A5")<br />
<br />
    'Loop through each cell in the range<br />
    For Each cell In sourceRange<br />
        'Split the text in the cell based on the delimiter<br />
        parts = Split(cell.Value, ",")<br />
<br />
        'Place the split parts in adjacent columns<br />
        cell.Offset(0, 1).Resize(1, UBound(parts) + 1).Value = parts<br />
    Next cell<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named SplitTextInCells.<br />
It declares variables for the source range (sourceRange), a loop variable (cell), and an array variable to hold the split parts (parts).<br />
Set sourceRange = Range("A1:A5") specifies the range A1:A5 where the text is located.<br />
The For Each loop is used to loop through each cell in the sourceRange.<br />
The Split function is used to split the text in the cell based on the delimiter ("," in this example). <br />
The result is stored in the array variable parts.<br />
The split parts are then placed in adjacent columns to the right of the original cell. <br />
cell.Offset(0, 1) refers to the cell next to the current cell, and Resize(1, UBound(parts) + 1) adjusts the size of the destination range to fit the number of split parts. <br />
The split parts are written to the destination range using .Value = parts.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub SplitTextInCells()<br />
    Dim sourceRange As Range<br />
    Dim cell As Range<br />
    Dim parts As Variant<br />
<br />
    'Set the range where the text is located (assuming data starts from A1)<br />
    Set sourceRange = Range("A1:A5")<br />
<br />
    'Loop through each cell in the range<br />
    For Each cell In sourceRange<br />
        'Split the text in the cell based on the delimiter<br />
        parts = Split(cell.Value, ",")<br />
<br />
        'Place the split parts in adjacent columns<br />
        cell.Offset(0, 1).Resize(1, UBound(parts) + 1).Value = parts<br />
    Next cell<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named SplitTextInCells.<br />
It declares variables for the source range (sourceRange), a loop variable (cell), and an array variable to hold the split parts (parts).<br />
Set sourceRange = Range("A1:A5") specifies the range A1:A5 where the text is located.<br />
The For Each loop is used to loop through each cell in the sourceRange.<br />
The Split function is used to split the text in the cell based on the delimiter ("," in this example). <br />
The result is stored in the array variable parts.<br />
The split parts are then placed in adjacent columns to the right of the original cell. <br />
cell.Offset(0, 1) refers to the cell next to the current cell, and Resize(1, UBound(parts) + 1) adjusts the size of the destination range to fit the number of split parts. <br />
The split parts are written to the destination range using .Value = parts.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Count colored cells with VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5265</link>
			<pubDate>Thu, 27 Jul 2023 13:07:58 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5265</guid>
			<description><![CDATA[Example:<br />
<br />
Sub CountColoredCells()<br />
    Dim countColor As Long<br />
    Dim cell As Range<br />
    Dim targetColor As Long<br />
<br />
    'Specify the target color (RGB value) to count<br />
    targetColor = RGB(255, 0, 0) 'Red color in this example<br />
<br />
    countColor = 0 'Initialize the counter<br />
<br />
    'Loop through each cell in the range<br />
    For Each cell In Range("A1:A10")<br />
        'Check if the cell's background color matches the target color<br />
        If cell.Interior.Color = targetColor Then<br />
            countColor = countColor + 1 'Increment the counter<br />
        End If<br />
    Next cell<br />
<br />
    MsgBox "Number of cells with the target color: " &amp; countColor<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CountColoredCells.<br />
It declares variables for the counter (countColor), a loop variable (cell), and the target color (targetColor) you want to count. <br />
In this example, we use the RGB value for the color red (255, 0, 0).<br />
The counter countColor is initialized to 0.<br />
The For Each loop is used to loop through each cell in the range "A1:A10".<br />
The If statement checks if the background color of the current cell matches the target color (targetColor = RGB(255, 0, 0)). <br />
If there is a match, the counter countColor is incremented by 1.<br />
Finally, a message box displays the number of cells with the target color.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub CountColoredCells()<br />
    Dim countColor As Long<br />
    Dim cell As Range<br />
    Dim targetColor As Long<br />
<br />
    'Specify the target color (RGB value) to count<br />
    targetColor = RGB(255, 0, 0) 'Red color in this example<br />
<br />
    countColor = 0 'Initialize the counter<br />
<br />
    'Loop through each cell in the range<br />
    For Each cell In Range("A1:A10")<br />
        'Check if the cell's background color matches the target color<br />
        If cell.Interior.Color = targetColor Then<br />
            countColor = countColor + 1 'Increment the counter<br />
        End If<br />
    Next cell<br />
<br />
    MsgBox "Number of cells with the target color: " &amp; countColor<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CountColoredCells.<br />
It declares variables for the counter (countColor), a loop variable (cell), and the target color (targetColor) you want to count. <br />
In this example, we use the RGB value for the color red (255, 0, 0).<br />
The counter countColor is initialized to 0.<br />
The For Each loop is used to loop through each cell in the range "A1:A10".<br />
The If statement checks if the background color of the current cell matches the target color (targetColor = RGB(255, 0, 0)). <br />
If there is a match, the counter countColor is incremented by 1.<br />
Finally, a message box displays the number of cells with the target color.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Calculate factorial of a given number in VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5264</link>
			<pubDate>Thu, 27 Jul 2023 13:04:03 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5264</guid>
			<description><![CDATA[Example:<br />
<br />
Function Factorial(number As Integer) As Double<br />
    Dim result As Double<br />
    Dim i As Integer<br />
<br />
    result = 1<br />
<br />
    'Calculate factorial<br />
    For i = 1 To number<br />
        result = result * i<br />
    Next i<br />
<br />
    Factorial = result<br />
End Function<br />
<br />
Sub CalculateFactorial()<br />
    Dim num As Integer<br />
<br />
    'Enter the number for which you want to calculate the factorial<br />
    num = 5<br />
<br />
    'Calculate and display the factorial using the Factorial function<br />
    MsgBox "Factorial of " &amp; num &amp; " is: " &amp; Factorial(num)<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a custom function named Factorial, which calculates the factorial of a given number.<br />
The Factorial function takes an integer number as input and returns a Double as the result.<br />
A variable result is initialized to 1, as the factorial of 0 is 1.<br />
The For loop runs from 1 to number, and in each iteration, the result is multiplied by i.<br />
The Factorial function returns the final result as the factorial of the input number.<br />
The CalculateFactorial subroutine demonstrates how to use the Factorial function.<br />
A number (5 in this example) is assigned to the variable num.<br />
The factorial of num is calculated using the Factorial function and displayed in a message box using MsgBox.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Function Factorial(number As Integer) As Double<br />
    Dim result As Double<br />
    Dim i As Integer<br />
<br />
    result = 1<br />
<br />
    'Calculate factorial<br />
    For i = 1 To number<br />
        result = result * i<br />
    Next i<br />
<br />
    Factorial = result<br />
End Function<br />
<br />
Sub CalculateFactorial()<br />
    Dim num As Integer<br />
<br />
    'Enter the number for which you want to calculate the factorial<br />
    num = 5<br />
<br />
    'Calculate and display the factorial using the Factorial function<br />
    MsgBox "Factorial of " &amp; num &amp; " is: " &amp; Factorial(num)<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a custom function named Factorial, which calculates the factorial of a given number.<br />
The Factorial function takes an integer number as input and returns a Double as the result.<br />
A variable result is initialized to 1, as the factorial of 0 is 1.<br />
The For loop runs from 1 to number, and in each iteration, the result is multiplied by i.<br />
The Factorial function returns the final result as the factorial of the input number.<br />
The CalculateFactorial subroutine demonstrates how to use the Factorial function.<br />
A number (5 in this example) is assigned to the variable num.<br />
The factorial of num is calculated using the Factorial function and displayed in a message box using MsgBox.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Generate random numbers in VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5263</link>
			<pubDate>Thu, 27 Jul 2023 13:03:08 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5263</guid>
			<description><![CDATA[Example:<br />
<br />
Sub GenerateRandomNumbers()<br />
    Dim i As Long<br />
<br />
    'Generate and place 10 random numbers in column A<br />
    For i = 1 To 10<br />
        Cells(i, "A").Value = Int((100 * Rnd) + 1)<br />
    Next i<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named GenerateRandomNumbers.<br />
It declares a loop counter i.<br />
The For loop runs from 1 to 10, generating ten random numbers.<br />
Rnd is used to generate a random number between 0 and 1. <br />
(100 * Rnd) generates a random number between 0 and 100, <br />
and Int((100 * Rnd) + 1) generates a random integer between 1 and 100.<br />
The generated random number is placed in column A for each iteration using Cells(i, "A").Value.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub GenerateRandomNumbers()<br />
    Dim i As Long<br />
<br />
    'Generate and place 10 random numbers in column A<br />
    For i = 1 To 10<br />
        Cells(i, "A").Value = Int((100 * Rnd) + 1)<br />
    Next i<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named GenerateRandomNumbers.<br />
It declares a loop counter i.<br />
The For loop runs from 1 to 10, generating ten random numbers.<br />
Rnd is used to generate a random number between 0 and 1. <br />
(100 * Rnd) generates a random number between 0 and 100, <br />
and Int((100 * Rnd) + 1) generates a random integer between 1 and 100.<br />
The generated random number is placed in column A for each iteration using Cells(i, "A").Value.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Concatenate data in columns]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5262</link>
			<pubDate>Thu, 27 Jul 2023 13:01:59 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5262</guid>
			<description><![CDATA[Example:<br />
<br />
Sub ConcatenateColumns()<br />
    Dim lastRow As Long<br />
    Dim i As Long<br />
<br />
    'Find the last row with data in column A<br />
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Loop through each row and concatenate values from columns A and B<br />
    For i = 1 To lastRow<br />
        Cells(i, "C").Value = Cells(i, "A").Value &amp; " " &amp; Cells(i, "B").Value<br />
    Next i<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named ConcatenateColumns.<br />
It declares variables for the last row with data (lastRow) and a loop counter (i).<br />
The lastRow variable is determined using Cells(Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A.<br />
The For loop iterates through each row from 1 to lastRow.<br />
In each iteration, the values from columns A and B are concatenated with a space (" ") in between, and the result is placed in column C using Cells(i, "C").Value.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub ConcatenateColumns()<br />
    Dim lastRow As Long<br />
    Dim i As Long<br />
<br />
    'Find the last row with data in column A<br />
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row<br />
<br />
    'Loop through each row and concatenate values from columns A and B<br />
    For i = 1 To lastRow<br />
        Cells(i, "C").Value = Cells(i, "A").Value &amp; " " &amp; Cells(i, "B").Value<br />
    Next i<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named ConcatenateColumns.<br />
It declares variables for the last row with data (lastRow) and a loop counter (i).<br />
The lastRow variable is determined using Cells(Rows.Count, "A").End(xlUp).Row, which finds the last row with data in column A.<br />
The For loop iterates through each row from 1 to lastRow.<br />
In each iteration, the values from columns A and B are concatenated with a space (" ") in between, and the result is placed in column C using Cells(i, "C").Value.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Calculate the avg and color the cells when their values are above or below the avg]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5261</link>
			<pubDate>Thu, 27 Jul 2023 12:41:34 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5261</guid>
			<description><![CDATA[Example:<br />
<br />
Sub CalculateAverageAndColorCode()<br />
    Dim dataRange As Range<br />
    Dim avgValue As Double<br />
    Dim cell As Range<br />
<br />
    'Set the range where you want to calculate the average and apply color coding<br />
    Set dataRange = Range("A1:A10")<br />
<br />
    'Calculate the average value of the range<br />
    avgValue = Application.WorksheetFunction.Average(dataRange)<br />
<br />
    'Color code cells based on whether their value is above or below the average<br />
    For Each cell In dataRange<br />
        If cell.Value &gt; avgValue Then<br />
            cell.Interior.Color = RGB(0, 255, 0) 'Green color for above average<br />
        ElseIf cell.Value &lt; avgValue Then<br />
            cell.Interior.Color = RGB(255, 0, 0) 'Red color for below average<br />
        End If<br />
    Next cell<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CalculateAverageAndColorCode.<br />
It declares variables for the data range (dataRange), the average value (avgValue), and a loop variable (cell) to iterate through each cell in the range.<br />
Set dataRange = Range("A1:A10") specifies the range A1:A10 where you want to calculate the average and apply color coding.<br />
The Application.WorksheetFunction.Average function is used to calculate the average value of the dataRange.<br />
The For Each loop is used to iterate through each cell in dataRange.<br />
If a cell's value is above the average, it is colored green using cell.Interior.Color = RGB(0, 255, 0).<br />
If a cell's value is below the average, it is colored red using cell.Interior.Color = RGB(255, 0, 0).]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub CalculateAverageAndColorCode()<br />
    Dim dataRange As Range<br />
    Dim avgValue As Double<br />
    Dim cell As Range<br />
<br />
    'Set the range where you want to calculate the average and apply color coding<br />
    Set dataRange = Range("A1:A10")<br />
<br />
    'Calculate the average value of the range<br />
    avgValue = Application.WorksheetFunction.Average(dataRange)<br />
<br />
    'Color code cells based on whether their value is above or below the average<br />
    For Each cell In dataRange<br />
        If cell.Value &gt; avgValue Then<br />
            cell.Interior.Color = RGB(0, 255, 0) 'Green color for above average<br />
        ElseIf cell.Value &lt; avgValue Then<br />
            cell.Interior.Color = RGB(255, 0, 0) 'Red color for below average<br />
        End If<br />
    Next cell<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CalculateAverageAndColorCode.<br />
It declares variables for the data range (dataRange), the average value (avgValue), and a loop variable (cell) to iterate through each cell in the range.<br />
Set dataRange = Range("A1:A10") specifies the range A1:A10 where you want to calculate the average and apply color coding.<br />
The Application.WorksheetFunction.Average function is used to calculate the average value of the dataRange.<br />
The For Each loop is used to iterate through each cell in dataRange.<br />
If a cell's value is above the average, it is colored green using cell.Interior.Color = RGB(0, 255, 0).<br />
If a cell's value is below the average, it is colored red using cell.Interior.Color = RGB(255, 0, 0).]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Protect specific cells with VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5260</link>
			<pubDate>Thu, 27 Jul 2023 12:39:12 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5260</guid>
			<description><![CDATA[Example:<br />
<br />
Sub ProtectSpecificCells()<br />
    Dim ws As Worksheet<br />
    Dim protectedRange As Range<br />
<br />
    'Set the worksheet where the cells are located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Set the range of cells to be protected (adjust the range as per your data)<br />
    Set protectedRange = ws.Range("B2<img src="https://qomplainerzschool.lima-city.de/images/smilies/biggrin.png" alt="Big Grin" title="Big Grin" class="smilie smilie_4" />10")<br />
<br />
    'Protect the specified cells with a password<br />
    ws.Protect Password:="mypassword", UserInterfaceOnly:=True<br />
    protectedRange.Locked = True<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named ProtectSpecificCells.<br />
It declares variables for the worksheet (ws) and the range of cells to be protected (protectedRange).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the cells are located.<br />
Set protectedRange = ws.Range("B2<img src="https://qomplainerzschool.lima-city.de/images/smilies/biggrin.png" alt="Big Grin" title="Big Grin" class="smilie smilie_4" />10") sets the range of cells B2 to D10 to be protected.<br />
The ws.Protect method is used to protect the entire worksheet with a password ("mypassword"). <br />
The UserInterfaceOnly:=True argument allows VBA code to modify protected cells without unprotecting the worksheet.<br />
protectedRange.Locked = True locks the specified cells within the protected worksheet.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub ProtectSpecificCells()<br />
    Dim ws As Worksheet<br />
    Dim protectedRange As Range<br />
<br />
    'Set the worksheet where the cells are located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Set the range of cells to be protected (adjust the range as per your data)<br />
    Set protectedRange = ws.Range("B2<img src="https://qomplainerzschool.lima-city.de/images/smilies/biggrin.png" alt="Big Grin" title="Big Grin" class="smilie smilie_4" />10")<br />
<br />
    'Protect the specified cells with a password<br />
    ws.Protect Password:="mypassword", UserInterfaceOnly:=True<br />
    protectedRange.Locked = True<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named ProtectSpecificCells.<br />
It declares variables for the worksheet (ws) and the range of cells to be protected (protectedRange).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the cells are located.<br />
Set protectedRange = ws.Range("B2<img src="https://qomplainerzschool.lima-city.de/images/smilies/biggrin.png" alt="Big Grin" title="Big Grin" class="smilie smilie_4" />10") sets the range of cells B2 to D10 to be protected.<br />
The ws.Protect method is used to protect the entire worksheet with a password ("mypassword"). <br />
The UserInterfaceOnly:=True argument allows VBA code to modify protected cells without unprotecting the worksheet.<br />
protectedRange.Locked = True locks the specified cells within the protected worksheet.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Find a specific value in a range and replace it with a new value]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5259</link>
			<pubDate>Thu, 27 Jul 2023 12:38:21 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5259</guid>
			<description><![CDATA[Example:<br />
<br />
Sub FindAndReplace()<br />
    Dim searchRange As Range<br />
    Dim findValue As Variant<br />
    Dim replaceValue As Variant<br />
<br />
    'Set the range where you want to find and replace values<br />
    Set searchRange = Range("A1:A10")<br />
<br />
    'Specify the value to find and the value to replace it with<br />
    findValue = "OldValue"<br />
    replaceValue = "NewValue"<br />
<br />
    'Find and replace the value in the range<br />
    searchRange.Replace What:=findValue, Replacement:=replaceValue, LookAt:=xlWhole<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named FindAndReplace.<br />
It declares variables for the search range (searchRange), the value to find (findValue), and the value to replace it with (replaceValue).<br />
Set searchRange = Range("A1:A10") specifies the range A1:A10 where you want to find and replace values.<br />
findValue = "OldValue" and replaceValue = "NewValue" set the values to be found and replaced, respectively.<br />
The searchRange.Replace method is used to find and replace the value. <br />
What:=findValue specifies the value to find, Replacement:=replaceValue specifies the value to replace it with, and LookAt:=xlWhole indicates that it should find whole matches.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub FindAndReplace()<br />
    Dim searchRange As Range<br />
    Dim findValue As Variant<br />
    Dim replaceValue As Variant<br />
<br />
    'Set the range where you want to find and replace values<br />
    Set searchRange = Range("A1:A10")<br />
<br />
    'Specify the value to find and the value to replace it with<br />
    findValue = "OldValue"<br />
    replaceValue = "NewValue"<br />
<br />
    'Find and replace the value in the range<br />
    searchRange.Replace What:=findValue, Replacement:=replaceValue, LookAt:=xlWhole<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named FindAndReplace.<br />
It declares variables for the search range (searchRange), the value to find (findValue), and the value to replace it with (replaceValue).<br />
Set searchRange = Range("A1:A10") specifies the range A1:A10 where you want to find and replace values.<br />
findValue = "OldValue" and replaceValue = "NewValue" set the values to be found and replaced, respectively.<br />
The searchRange.Replace method is used to find and replace the value. <br />
What:=findValue specifies the value to find, Replacement:=replaceValue specifies the value to replace it with, and LookAt:=xlWhole indicates that it should find whole matches.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Create a pivot table based on data in a worksheet with VBA]]></title>
			<link>https://qomplainerzschool.lima-city.de/showthread.php?tid=5258</link>
			<pubDate>Thu, 27 Jul 2023 11:48:27 +0200</pubDate>
			<dc:creator><![CDATA[<a href="https://qomplainerzschool.lima-city.de/member.php?action=profile&uid=1">Qomplainerz</a>]]></dc:creator>
			<guid isPermaLink="false">https://qomplainerzschool.lima-city.de/showthread.php?tid=5258</guid>
			<description><![CDATA[Example:<br />
<br />
Sub CreatePivotTable()<br />
    Dim ws As Worksheet<br />
    Dim pt As PivotTable<br />
    Dim ptCache As PivotCache<br />
    Dim ptRange As Range<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Set the range of data for the pivot table (adjust the range as per your data)<br />
    Set ptRange = ws.Range("A1:B10")<br />
<br />
    'Create a new pivot cache based on the data range<br />
    Set ptCache = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=ptRange)<br />
<br />
    'Create a new pivot table on a new worksheet<br />
    Set pt = ptCache.CreatePivotTable(TableDestination:=ws.Cells(1, 4), TableName:="MyPivotTable")<br />
    With pt<br />
        .PivotFields("Category").Orientation = xlRowField<br />
        .AddDataField .PivotFields("Value"), "Sum of Value", xlSum<br />
    End With<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CreatePivotTable.<br />
It declares variables for the worksheet (ws), pivot table (pt), pivot cache (ptCache), and the range of data for the pivot table (ptRange).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
The ptRange variable is set to the range of data for the pivot table (A1:B10 in this example).<br />
A new pivot cache is created based on the data range using ThisWorkbook.PivotCaches.Create.<br />
The pivot table is created on a new worksheet at cell D1 (TableDestination:=ws.Cells(1, 4)) with the name "MyPivotTable" using ptCache.CreatePivotTable.<br />
The With block is used to customize the pivot table. <br />
In this example, the "Category" field is set as a row field, and the "Value" field is added as a data field with the aggregation function xlSum.]]></description>
			<content:encoded><![CDATA[Example:<br />
<br />
Sub CreatePivotTable()<br />
    Dim ws As Worksheet<br />
    Dim pt As PivotTable<br />
    Dim ptCache As PivotCache<br />
    Dim ptRange As Range<br />
<br />
    'Set the worksheet where the data is located<br />
    Set ws = ThisWorkbook.Sheets("Sheet1")<br />
<br />
    'Set the range of data for the pivot table (adjust the range as per your data)<br />
    Set ptRange = ws.Range("A1:B10")<br />
<br />
    'Create a new pivot cache based on the data range<br />
    Set ptCache = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=ptRange)<br />
<br />
    'Create a new pivot table on a new worksheet<br />
    Set pt = ptCache.CreatePivotTable(TableDestination:=ws.Cells(1, 4), TableName:="MyPivotTable")<br />
    With pt<br />
        .PivotFields("Category").Orientation = xlRowField<br />
        .AddDataField .PivotFields("Value"), "Sum of Value", xlSum<br />
    End With<br />
End Sub<br />
<br />
Explanation:<br />
<br />
The code defines a subroutine named CreatePivotTable.<br />
It declares variables for the worksheet (ws), pivot table (pt), pivot cache (ptCache), and the range of data for the pivot table (ptRange).<br />
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.<br />
The ptRange variable is set to the range of data for the pivot table (A1:B10 in this example).<br />
A new pivot cache is created based on the data range using ThisWorkbook.PivotCaches.Create.<br />
The pivot table is created on a new worksheet at cell D1 (TableDestination:=ws.Cells(1, 4)) with the name "MyPivotTable" using ptCache.CreatePivotTable.<br />
The With block is used to customize the pivot table. <br />
In this example, the "Category" field is set as a row field, and the "Value" field is added as a data field with the aggregation function xlSum.]]></content:encoded>
		</item>
	</channel>
</rss>