Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

New to the forum and very new to Macros. I am trying to get rid of the TRUE dialog box every time I run the macro below and not sure how to accomplish that?

Thanks in advance!!



Code:
Sub CheckBox372_Click()

    If ActiveSheet.Shapes(Application.Caller).ControlFormat.Value = 1 Then
        MsgBox Range("E2").Select
    Selection.Copy
    Range("D2").Select
    ActiveSheet.Paste
    Range("K2").Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=MID(RC[-7],10,3)+RC[2]"
    Range("K2").Select
Else
        MsgBox Range("D2").Select
    Selection.ClearContents
End If
    
End Sub
 
Fluff, YES it works great except instead of a "PASTE" it needs to be a "PASTE SPECIAL-Value" so it doesn't mess up the cell formatting with shading and borders. Then on the "Uncheck" we need to restore the =MID(D2,10,3) with a "PASTE SPECIAL-Formula" in column K and return to Column D like below

Code:
Range("D2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False    Selection.Copy

Code:
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
[FONT=Verdana]SkipBlanks:=False, Transpose:=False[/FONT]
 
Last edited:
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Ok, how about
Code:
Sub Buns1976()
   Dim Shp As Shape
   
   Set Shp = ActiveSheet.Shapes(Application.Caller)
   With Shp.TopLeftCell
      If Shp.ControlFormat.Value = 1 Then
         Cells(.Row, "D").Value = Cells(.Row, "E").Value
         Cells(.Row, "K").FormulaR1C1 = "=MID(RC[-7],10,3)+RC[2]"
         Cells(.Row, "K").Select
      Else
         Cells(.Row, "D").ClearContents
         Cells(.Row, "K").FormulaR1C1 = "=mid(rc[-7],10,3)"
         Cells(.Row, "D").Select
      End If
    End With
End Sub
 
Upvote 0
Getting closer! These numbers are formatted as text because some have a leading zero like this. 09870221601295. When I run the macro it returns 9870221601295 which messes up the MID plus some other formulas. It wasn't doing that previously!


Edit: When i do a "PASTE SPECIAL-Value" manually it keeps the leading 0 so not sure
 
Last edited:
Upvote 0
OK,
Code:
      If Shp.ControlFormat.Value = 1 Then
         Cells(.Row, "E").Copy
         Cells(.Row, "D").PasteSpecial xlPasteValues
         Cells(.Row, "K").FormulaR1C1 = "=MID(RC[-7],10,3)+RC[2]"
         Cells(.Row, "K").Select
      Else
 
Upvote 0
That my friend appears to be a winner!!! If you something were to change I'll post back and by the way, I found out what happens when the checkbox is ever so slightly outside of the cell in a hurry.
Thank you ever so kindly Fluff!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Hi again Fluff,
I just realized that the cell the macro is repopulating on the uncheck has to be unprotected which is a huge security issue for me.
Would you have any suggestions on a work around for that other than UnProtecting the sheet?
 
Last edited:
Upvote 0
Add these two lines to the code, the first at the start & the second at the end
Code:
ActiveSheet.Unprotect "pword"
ActiveSheet.Protect "pword"
Change pword to whatever you password is
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,661
Members
449,114
Latest member
aides

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