Macro that will copy values in Column J and paste values to Column B in new sheet

Phixtit

Active Member
Joined
Oct 23, 2008
Messages
346
I have a macro that will copy Sheet, Create & name a new Sheet & Paste sheet to the new Sheet.

When it copies Sheet I need it to move the values in column J and Paste them into Column B.

Here is my module code: (Shown in Red is what I've been trying)
Code:
Sub MyButtons()

Dim CurrentDay As Integer, NewName As String
Dim checkWs As Worksheet, OldWs As Worksheet
Set OldWs = ActiveSheet
ActiveSheet.Unprotect ("1212")
If IsNumeric(Right(ActiveSheet.Name, 2)) Then
    CurrentDay = Right(ActiveSheet.Name, 2)
    ElseIf IsNumeric(Right(ActiveSheet.Name, 1)) Then
CurrentDay = Right(ActiveSheet.Name, 1)
Else
    Exit Sub
End If
If CurrentDay >= 30 Then
    MsgBox "You cannot go higher than 30"
    Exit Sub
End If
CurrentDay = CurrentDay + 1
NewName = "DAY " & CurrentDay
On Error Resume Next
Set checkWs = Worksheets(NewName)
If checkWs Is Nothing Then
    Worksheets(ActiveSheet.Name).Copy After:=Worksheets(ActiveSheet.Index)
    With ActiveSheet
.Name = NewName
[COLOR=Red].Range("J7:J1048576").Copy
.Range("B7:B1048576").Paste[/COLOR]

ActiveSheet.Unprotect ("1212")
.Range("S4").Value = Range("S4").Value + 1
.Range("L2").Value = Range("L2").Value + 1
[COLOR=Red].Range("J7:J1048576").Value = Range("B7:B1048576").Paste[/COLOR]

Dim strFrmla As String
strFrmla = Application.ConvertFormula(.Range("S8").Formula, xlA1, xlR1C1, toabsolute:=True)
.Range("S8").FormulaR1C1 = Left(strFrmla, InStrRev(strFrmla, "C")) & CLng(Mid(strFrmla, InStrRev(strFrmla, "C") + 1)) + 1

strFrmla = Application.ConvertFormula(.Range("S9").Formula, xlA1, xlR1C1, toabsolute:=True)
.Range("S9").FormulaR1C1 = Left(strFrmla, InStrRev(strFrmla, "C")) & CLng(Mid(strFrmla, InStrRev(strFrmla, "C") + 1)) + 1

strFrmla = Application.ConvertFormula(.Range("S10").Formula, xlA1, xlR1C1, toabsolute:=True)
.Range("S10").FormulaR1C1 = Left(strFrmla, InStrRev(strFrmla, "C")) & CLng(Mid(strFrmla, InStrRev(strFrmla, "C") + 1)) + 1

strFrmla = Application.ConvertFormula(.Range("V14").Formula, xlA1, xlR1C1, toabsolute:=True)
.Range("V14").FormulaR1C1 = Left(strFrmla, InStrRev(strFrmla, "C")) & CLng(Mid(strFrmla, InStrRev(strFrmla, "C") + 1)) + 1

strFrmla = Application.ConvertFormula(.Range("V15").Formula, xlA1, xlR1C1, toabsolute:=True)
.Range("V15").FormulaR1C1 = Left(strFrmla, InStrRev(strFrmla, "C")) & CLng(Mid(strFrmla, InStrRev(strFrmla, "C") + 1)) + 1

ActiveSheet.Protect ("1212")
    End With
Else
    Set checkWs = Nothing
    MsgBox "A Worksheet named " & NewName & " already exists."
End If
ActiveSheet.Protect ("1212")
OldWs.Protect ("1212")
End Sub
Below is the form code to call the module above:
Code:
Private Sub Day2_Click()
    Dim TargetSheet As Worksheet
    On Error Resume Next
    Sheet2.Select
    Set TargetSheet = Sheets("Day 2")
    On Error GoTo 0
    If TargetSheet Is Nothing Then
    
    If MsgBox("Would you like to add a Day?", vbOKCancel) = vbOK Then

Call MyButtons
    Unload Me
    Else
    Exit Sub
    
    End If
    MsgBox "You have successfully added a day."
    Else
    Unload Me
    
    End If
End Sub
Any ideas on how this can be accomplished?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try:
Code:
    .Range("J7:J1048576").Copy .Range("B7:B1048576")
Otherwise do the step manually with the macro recorder running to generate the VBA code.
 
Upvote 0
Solved! :)

Thanks,
Here is the solution:
Code:
[FONT=Arial][SIZE=2][COLOR=#000000].Range("B7:B1048576").Value=.Range("J7:J1048576").value[/COLOR][/SIZE][/FONT]</pre>
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,628
Members
449,241
Latest member
NoniJ

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