I need help Editing this Macro

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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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
        '[COLOR=#ff0000]MsgBox Range("E2").Select[/COLOR]
    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
        '[COLOR=#ff0000]MsgBox Range("D2").Select  [/COLOR] 
    Selection.ClearContents
End If
    
End Sub

Try commenting or removing those 2 lines of code.
 
Upvote 0
I tried deleting those 2 lines BUT then the macro doesn't do what is expected. Not sure what you mean be "commenting"?
 
Upvote 0
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
        [COLOR=#ff0000]Range("E2").Select[/COLOR]
    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
        [COLOR=#ff0000]Range("D2").Select[/COLOR]
    Selection.ClearContents
End If
    
End Sub

Then please try by just removing the "MsgBox" Function.
 
Upvote 0
Aw sweet! That works! Thank you kindly!

I have a 2nd question and not sure if I need to start a new thread or not?

As you see this macro runs on row 2. I have 70 more rows with check boxes that require the same macro. Is there a way to copy this down or do I need to create 70 macros since they are row specific?
 
Upvote 0
That depends, you could just copy this code to each checkbox Sub, and modify the cell ranges as per your needs.
 
Upvote 0
Thats what I was afraid of! LOL Any other solutions to this as you indicated "That depends"?
 
Upvote 0
You could assign this macro to all the checkboxes
Code:
Sub Buns1976()
   Dim Shp As Shape
   
   Set Shp = ActiveSheet.Shapes(Application.Caller)
   With Shp.TopLeftCell
      If Shp.ControlFormat.Value = 1 Then
         Cells(.Row, "E").Copy Cells(.Row, "D")
         Cells(.Row, "K").FormulaR1C1 = "=MID(RC[-7],10,3)+RC[2]"
         Cells(.Row, "K").Select
      Else
         Cells(.Row, "D").ClearContents
      End If
    End With
End Sub
The top left corner of the checkbox needs to be on the row it should work on
 
Upvote 0
Fluff, I messed something up on my Macro. I failed to appreciate that the "Uncheck" part wasn't restoring a formula so now I have the macro below however when debugging I am getting the compile error "Else without if"? Once that get fixed how does that play into your solution in the previous post?

Code:
Sub CheckBox373_Click()

     Range("E2").Select
    Selection.Copy
    Range("D2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("K2").Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=MID(RC[-7],10,3)+RC[2]"
    Range("D2").Select
Else
       Range("D2").Select
    Selection.ClearContents
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 5
    Range("U2").Select
    Selection.Copy
    Range("K2").Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Range("D2").Select
End If
    
End Sub
 
Upvote 0
Try the code I posted & if it works we can then modify it.
Lets get that sorted first.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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