Excel Macro to duplicate info based on value in another cell
Closed
patrick.gilchrist
Posts
1
Registration date
Friday 28 April 2023
Status
Member
Last seen
28 April 2023
-
28 Apr 2023 à 11:41
Aron_7608 Posts 3 Registration date Tuesday 15 December 2020 Status Member Last seen 15 May 2023 - 15 May 2023 à 02:31
Aron_7608 Posts 3 Registration date Tuesday 15 December 2020 Status Member Last seen 15 May 2023 - 15 May 2023 à 02:31
Related:
- Excel Macro to duplicate info based on value in another cell
- Outlook duplicate items remover (odir) - Download - Email
- Excel online macros - Guide
- Crystal disk info - Download - Diagnosis and monitoring
- Excel run macro on open - Guide
- Excel mod apk for pc - Download - Spreadsheets
1 response
Aron_7608
Posts
3
Registration date
Tuesday 15 December 2020
Status
Member
Last seen
15 May 2023
15 May 2023 à 02:31
15 May 2023 à 02:31
Hey patrick,
Yes, it is possible to create a macro in Excel that duplicates a range of cells based on the value in a specific cell. Here's an example VBA code that can do it-
Sub DuplicateCells()
Dim rngSource As Range
Dim rngDestination As Range
Dim count As Long
Dim i As Long
' Set the source range to be duplicated
Set rngSource = Range("C6:E34")
' Get the number of locations from cell D5
count = Range("D5").Value
' Clear any existing duplicated ranges
Range("C6:E34").ClearContents
' Loop through the count and duplicate the range
For i = 1 To count
' Calculate the destination range for each duplication
Set rngDestination = rngSource.Offset((i - 1) * rngSource.Rows.Count, 0)
' Copy and paste values from the source to the destination range
rngSource.Copy
rngDestination.PasteSpecial Paste:=xlPasteValues
Next i
' Clear the clipboard
Application.CutCopyMode = False
End Sub
In this code, the DuplicateCells subroutine is triggered when the value in cell D5 is changed. It clears any existing duplicated ranges and then duplicates the range C6:E34 based on the count specified in cell D5. The duplicated ranges are pasted as values to avoid any formula dependencies.
You can assign this macro to a button or run it manually whenever you want to duplicate the range.
I hope this helps. :)
Best Regards.
