Macro to copy data using button to worksheets based on drop down value

vee_vee8

New Member
Joined
Feb 6, 2020
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I was really hoping someone would be able to help me with a macro for this. I've attempted to review solutions in other forums but my vba knowledge is pretty basic so I'm out of my depth here.

I have a spreadsheet where information is added to a worksheet called 'Data Entry', information is added in cells, C11:C13, C16:C19, C22:C26 and C29:C32 daily. There is a drop down at cell B9 which relates to the names of the different sheets. I was hoping to see if there was a way that when the drop-down option was selected that the data could be copied across with a button to the corresponding sheet?

Any advice would be greatly appreciated.
 

Attachments

  • Screenshot 1.jpg
    Screenshot 1.jpg
    118.6 KB · Views: 5
  • Screenshot 2.jpg
    Screenshot 2.jpg
    111.8 KB · Views: 4
  • Screenshot 3.jpg
    Screenshot 3.jpg
    151.4 KB · Views: 5

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Are all your sheets - W1-D1, W1-D2 etc structured the same way; i.e. do the destination tables all start in row 30 (first header) in each of the sheets?
 
Upvote 0
Try the following on a copy of your workbook.

VBA Code:
Option Explicit
Sub VeeVee8()
    Dim ws As Worksheet, s As String, i As Long, exists As Boolean
    Set ws = Worksheets("Data Entry")
    s = ws.Range("B9")
    
    'Check if sheet exists
    For i = 1 To Worksheets.Count
    If Worksheets(i).Name = s Then
        exists = True
    End If
    Next i
    If Not exists Then
        MsgBox "The sheet " & s & " doesn't exist in this workbook"
        Exit Sub
    End If
    
    ws.Range("C10:C32").Copy Worksheets(s).Range("B30")
End Sub
 
Upvote 0
Solution
Try the following on a copy of your workbook.

VBA Code:
Option Explicit
Sub VeeVee8()
    Dim ws As Worksheet, s As String, i As Long, exists As Boolean
    Set ws = Worksheets("Data Entry")
    s = ws.Range("B9")
   
    'Check if sheet exists
    For i = 1 To Worksheets.Count
    If Worksheets(i).Name = s Then
        exists = True
    End If
    Next i
    If Not exists Then
        MsgBox "The sheet " & s & " doesn't exist in this workbook"
        Exit Sub
    End If
   
    ws.Range("C10:C32").Copy Worksheets(s).Range("B30")
End Sub
Thank you so much! That worked perfectly. Really appreciate your help!!!
 
Upvote 0

Forum statistics

Threads
1,215,174
Messages
6,123,451
Members
449,100
Latest member
sktz

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