Excel Macro for checkbox if true - vba

i need a macro or a line to add to my code for when the checkbox is true or "Checked" i need it to copy the content of a specific cell into another in a sheet in the same workbook what i was able to get to is this code
Sub macro2()
Range("A1:C4").Select
Selection.Copy
Sheets("sheet2").Select
Range("A1:C4").Select
ActiveCell.PasteSpecial
End Sub
but as you can see it only gets me to get this range to be copied and pasted once i have checked the box what i need is to copy it when checked and maybe not to let it get m to the cell in sheet2 to allow multiple selections to be pasted in some specified cells i know i have the code sheet2.select but i honestly don't know any other coding and i need to put that kind of coding for over hundred cells so do appreciate your assistance with this if anybody can please am dying here

If CheckBox1.Value = True Then
ThisWorkbook.Sheets("Sheet2").Range("A1:C4").Value = ThisWorkbook.Sheets("Sheet1").Range("A1:C4").Value
End if

Related

Mirroring Sheet1 to Sheet2 for Interior Color only, through VBA

I have a schedule showing a lot of information. I would like to condense this onto a second sheet that displays the fill color only and none of the values.
I want that any fill color changes are automatically copied from sheet1 to sheet2.
I want the code to work with a specific cell range as they differ from both sheets, (Sheet1 is "D8:QP27) & (Sheet2 is B3:QN22) and to get it to mirror at all.
Sheet1 showing all information
Sheet2 showing fill (Interior.Color)
It looks as if you also want to copy the borders (eg the diagonal border of column I), so I would suggest you use PasteSpecial with the option xlPasteFormats. See https://learn.microsoft.com/en-us/office/vba/api/excel.range.pastespecial
With ThisWorkbook
.Worksheets("Sheet1").Range("D8:QP27").Copy
.Worksheets("Sheet2").Range("B3:QN22").PasteSpecial xlPasteFormats
End With
Update: As you are looking for a trigger to copy the format automatically. First step is to create a subroutine:
Sub copyFormat()
Application.ScreenUpdating = False
With ThisWorkbook
.Worksheets("Sheet1").Range("D8:QP27").Copy
.Worksheets("Sheet2").Range("B3:QN22").PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
Application.ScreenUpdating = True
End Sub
Now you need to find a way to call the code, eg
o call the routine from the Worksheet_SelectionChange-event (drawback: as this is rather slow, it could annoy the user)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
copyFormat
End Sub
o Place a button on the sheet to call the routine.
o Use a Timer to call the routine every n seconds (see https://learn.microsoft.com/en-us/office/vba/api/excel.application.ontime). Plenty of examples on SO and elsewhere

Command button to paste table based on cell value

I have an Excel sheet in which I'm trying to make a walkthrough type of thing, for training new employees. At its core, I want to have a dropdown menu (got that already) filled with options, and then a command button that will check the contents of the drop down cell, and copy-paste a table from a hidden sheet onto the main sheet. For some reason, I can't get the button to work. This is what I've got so far:
Private Sub button_desk_Click()
Application.ScreenUpdating = False
'Create Table
If Worksheets("Walkthrough").Range("A2").Value2 = "Getting your desk set up" Then
Sheets("Settings").Select
Range("lookup_desksetup[[#All],[Getting your desk setup]]").Select
Selection.Copy
Sheets("Walkthrough").Select
Range("B5").Select
ActiveSheet.Paste
End If
Application.ScreenUpdating = True
End Sub
I've tried a few different approaches for this, including not using the .Select command, but I can't seem to get anything to work.
Sheets("Settings").Select
Range("lookup_desksetup[[#All],[Getting your desk setup]]").Select
Selection.Copy
Sheets("Walkthrough").Select
Range("B5").Select
ActiveSheet.Paste
is a long winded way of saying
Sheets("Settings").Range("lookup_desksetup[[#All],[Getting your desk setup]]").copy _
destination:= Sheets("Walkthrough").Range("B5")
However I suspect that your problem is that "lookup_desksetup[[#All],[Getting your desk setup]]" is a very funny range name and may not actually exist as a valid name in that sheet?

Excel Macro Copy Paste REF! Error

I am currently new to excel macros and trying to figure out why this is not working. Basically, I want Cell "D22" from "Sheet1" to be copied and then pasted to "sheet2" Cell "A2". The problem is on sheet1 I have a formula in cell D22 so when I copy and paste it into the new sheet, I get a #REF! ERROR :(
I have looked it up and tried fixing it but still no luck. Below is my basic code. I know there is probably a simple solution but if someone could please advise me in the right direction much would be appreciated! xD
Sub Insert()
Sheets("Sheet1").Select
Range("D22").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A2").Select
ActiveSheet.Paste
End Sub
If you just want to assign the value of one cell to another, don't use copy/paste, just use the Value property:
Sub Insert()
Sheets("Sheet2").Range("A2").Value = Sheets("Sheet1").Range("D22").Value
End Sub

VBA Code to copy and paste active column with merged cells inside

I'm trying to copy the active column and paste it next to it but the code selects the entire worksheet because it has merged cells in.
Sub CopyPaste()
Columns(ActiveCell.Column).Selection
Selection.Copy
ActiveCell.Offset(0,1).PasteSpecial Paste:=xlPasteAll
End Sub
Could you please help me adding the missing code to ignore merged cells?
This is yet another reason to avoid using Select in VBA for Excel. Your selection will expand with the merged cells. You can try this:
ActiveCell.EntireColumn.Copy ActiveCell.Offset(0, 1).EntireColumn
And again, you should find some way to avoid counting on the ActiveCell in your code, and use some fully qualified range.

Copy Cell To Another Sheet, one after another

I have been trying to find the solution to this for a while now and I do not believe I am searching for the right thing.
Basically what I want to do is copy a cell contents and paste it to another sheet and then delete the contents of the cell that was copied from.
I have one button that corresponds to each cell and I want to write a bit of code which enables you to do this at the click of a button.
Another issue is I don't know the code that would not constantly paste in the same cell over and over, but rather go to the next row and paste there.
What I have at the moment is the following:
Sub Macro1()
Range("I2").Select
Selection.Copy
Sheets("Completed Tasks").Select
Range("A72").Select
ActiveSheet.Paste
Sheets("Projects Live!").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Range("H2").Select
End Sub
This only refers to the top cell and i have recorded a macro to show essentially what i want.
Hope you can help or point me in the right direction.
Consider:
Sub luxation()
Range("I2").Copy Sheets("Completed Tasks").Range("A72")
Range("I2").Clear
End Sub
This is for a single cell...............you would embed this kind of syntax in a loop.