VBA to copy and paste information from c4:c25 in worksheet 1 to a specific tab selected in cell 4?

K_Stevs1

New Member
Joined
Jan 27, 2022
Messages
27
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi I have previously managed to copy and paste cells from one worksheet (named: Form) to another Worksheet (selected in Cell C4).

this is my current code and screenshot:

VBA Code:
Sub Copy_Data()
  Dim hh As Worksheet, exist As Boolean, h As Worksheet, sh As Worksheet
  Dim f As Range
 
  Set hh = Sheets("Form")
  If hh.Range("C4") = "" Then
    MsgBox "Enter Hospital", vbCritical
    Exit Sub
  End If
  If hh.Range("C5") = "" Then
    MsgBox "Enter Ward", vbCritical
    Exit Sub
  End If
  exist = False
  For Each h In Sheets
    If LCase(h.Name) = LCase(hh.Range("C4").Value) Then
      Set sh = h
      exist = True
      Exit For
    End If
  Next
  If exist = False Then
    MsgBox "The sheet does not exist", vbCritical
    Exit Sub
End If
Next
    'Copy Responses to Data'

    'cell destination             cell origin
    Copy.Paste hh.Range("C4:C25") = sh.Cells(f.Row, "A:V")
 
 'copy Resposes IF  Urinary Tract IS SELECTED'
'copy Reposes to the Sites Selected on the form cell C4'

'then give message'

 If MsgBox("Form Successfully Submitted!") Then
End If


End Sub

Form: Picture 1

Tabs: Picture 2

Any help is much appreciated.
 

Attachments

  • 1660844409785.png
    1660844409785.png
    28.6 KB · Views: 15
  • 1660844459296.png
    1660844459296.png
    1.8 KB · Views: 15

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,702
Messages
6,173,931
Members
452,539
Latest member
delvey

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