Basic VBA Copy Paste

SensualCarrots

New Member
Joined
Mar 21, 2015
Messages
46
I found several thing out there that get me close, but I don't really know VBA at all, so trying to modify to my needs was, well... rather unsuccessful. I need a rather simple macro.

Basically,

If A25 is empty, copy F24 and paste values in A25, else if A26 is empty, copy F24 and paste values in A26, else if A27 is empty..... and so forth down to A33, and if A33 is not empty, then end and do nothing. F24 is derived from a formula, so it's very important to paste special: paste values.

I also need a macro that will basically clear the form, and wipe out any data in a wide range of cells that I can select. Any help would be appreciated! Thanks!
 
Ok so I still have a problem. My clear contents command works fine, except when the sheet is protected. None of the cells I am trying to clear are locked, but I still get the error. I copied this from another workbook that I did something similar, and it has no problem clearing contents of unlocked cells on a protected sheet. Any ideas?
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Combine both our codes and add error handling that should tell you exactly what cell is causing issues:
Code:
Sub Button3_Click()

    Dim Answer
    Dim rng1 As Range
    Dim cell As Range
    
    Set rng1 = Sheets("Sheet1").Range("B1:B6, C2:F2, G4:H12, A19, B20, A22, B23, A25:B33, A35:B35, F21:F22")
    
    Answer = MsgBox("Are you sure you want to clear All User Data? This cannot be undone!", vbYesNoCancel + vbInformation, "Application Message")
    If Answer = vbYes Then Else Exit Sub
    
    On Error GoTo err_chk
    For Each cell In rng1
        cell.ClearContents
    Next cell
    On Error GoTo 0
    
    Exit Sub


err_chk:
    If Err.Number = 1004 Then
        MsgBox "Cell " & cell.Address(0, 0) & " is locked and cannot be cleared", vbOKOnly, "ERROR!"
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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