Check if cells are empty before pasting values

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Morning,
Im having an issue with the code below & now confused myself.

Previously i had just copied / pasted the values.
I have now see nothing is in place should i paste over value already in the cells as shown.
I have added the If IsEmpty code to check if cells have values & if Yes then just show msgbox but if empty then allow the paste of values to contine.
This is where ive now confused myself.

Rich (BB code):
Private Sub MayButton_Click()
If IsEmpty(Range"(E4:E13").Value)= True Then
MsgBox "CELLS HAVE VALUES OVERWRITE ?", VbYesNo"
If answer = vbYes Then
  MsgBox "Yes"
Else
  MsgBox "Calls Have Values"
Exit Sub
End If

Range("I9:I18").Copy Destination:=Range("E4:E13")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR
Range("I9:I18").ClearContents
Range("I9").Select
End Sub
 
Move the copy code OUTSIDE of your IF blocks, i.e.
VBA Code:
Private Sub MayButton_Click()

If WorksheetFunction.CountA(Range("E4:E13")) > 0 Then
    answer = MsgBox("CELLS CONTAIN VALUES ALREADY, OVERWRITE THEM ?", vbCritical + vbYesNo)
    If answer = vbNo Then
        Exit Sub
    End If
End If
    
Range("I9:I18").Copy Destination:=Range("E4:E13")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR
Range("I9:I18").ClearContents
Range("I9").Select

End Sub
 
Upvote 0
Solution

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Thanks,now done.
I was just overthinking it far too much.

Have a nice day
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
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