VBA - Select a cell in a certain column based on fill color and paste data from a different sheet with loop

acook1312

New Member
Joined
Nov 17, 2022
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi Everyone,

I'm creating a spreadsheet to help track work projects. I'm struggling to create a Macro to paste a new project template in the correct location every time.

Here's what I'm hoping to do:

1. Go to "Template" tab
2. Copy cells B7 through U18
3. Go to "P# Projects" tab
4. Paste copied data to the first grey cell in column B after the last project (In the image this would be B28)
5. I'd like a prompt that asks "Number of new parts" where I can enter a number and the process repeats that many times (IE if I have 5 new parts, I get five new templates pasted

Step 4 and 5 are what I'm struggling with. Any assistance would be appreciated.

Thanks

 

Attachments

  • Project Tracker.png
    Project Tracker.png
    126.1 KB · Views: 24
  • Project Tracker - Template.png
    Project Tracker - Template.png
    61.3 KB · Views: 20

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hello. Enjoy:
VBA Code:
Sub test()
    Dim lastRow As Long
    Dim enterText As String
    Dim numberOfIterations As Integer
    Application.ScreenUpdating = False
    enterText = InputBox("Number of new parts", "Enter a number", "Enter a number here")
    On Error Resume Next
    numberOfIterations = CInt(enterText)
    If IsNumeric(numberOfIterations) = True And numberOfIterations > 0 Then
        ActiveWorkbook.Worksheets("Template").Activate
        ActiveWorkbook.Worksheets("Template").Range(Cells(7, 2), Cells(18, 21)).Select
        Selection.Copy
        ActiveWorkbook.Worksheets("P# Projects").Activate
        For i = 1 To numberOfIterations
            lastRow = Range("C:C").Find("WOR/RTS", after:=Cells(1, 3), searchdirection:=xlPrevious).Row
            ActiveWorkbook.Worksheets("P# Projects").Cells(lastRow + 2, 2).Select
            ActiveSheet.Paste
        Next i
    Else
        MsgBox "You didn't input a number or your number is <1!", vbCritical
        Application.ScreenUpdating = True
        Exit Sub
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Hello. Enjoy:
VBA Code:
Sub test()
    Dim lastRow As Long
    Dim enterText As String
    Dim numberOfIterations As Integer
    Application.ScreenUpdating = False
    enterText = InputBox("Number of new parts", "Enter a number", "Enter a number here")
    On Error Resume Next
    numberOfIterations = CInt(enterText)
    If IsNumeric(numberOfIterations) = True And numberOfIterations > 0 Then
        ActiveWorkbook.Worksheets("Template").Activate
        ActiveWorkbook.Worksheets("Template").Range(Cells(7, 2), Cells(18, 21)).Select
        Selection.Copy
        ActiveWorkbook.Worksheets("P# Projects").Activate
        For i = 1 To numberOfIterations
            lastRow = Range("C:C").Find("WOR/RTS", after:=Cells(1, 3), searchdirection:=xlPrevious).Row
            ActiveWorkbook.Worksheets("P# Projects").Cells(lastRow + 2, 2).Select
            ActiveSheet.Paste
        Next i
    Else
        MsgBox "You didn't input a number or your number is <1!", vbCritical
        Application.ScreenUpdating = True
        Exit Sub
    End If
    Application.ScreenUpdating = True
End Sub

This worked perfectly, thank you!

Here's another question I have on the same document if you think you could help here too!

 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top