VBA Copy and Paste Not Working

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
Issue: Everything works fine with this code, but the last section which is marked not working.

Objective:To copy the value from one worksheet to the other.

Code:
Private Sub CommandButton1_Click()
Dim text As String
Dim i As Integer
For i = 0 To Me.ListBox1.ListCount - 1
    If Me.ListBox1.Selected(i) Then
        text = text & Me.ListBox1.List(i) & vbNewLine
    End If
Next i
MsgBox "Items you selected: " & vbNewLine & text
GetSelectedItemsText = text
Dim wks As Worksheet
For Each wks In ActiveWindow.SelectedSheets
 
    wks.Select
    Range("G3:G9").Select
    Selection.Copy
    Sheets("SPA_SummaryVIEW").Select
    Range("C6").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    wks.Select
    Range("O1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_SummaryVIEW").Select
    Range("C5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("C:C").EntireColumn.AutoFit
    Range("C6").Select
    Application.CutCopyMode = False
    Selection.Style = "Percent"
    Selection.NumberFormat = "0.0%"
    Selection.NumberFormat = "0.00%"
    Range("C7:C12").Select
    Selection.Style = "Currency"
    Range("C4").Select

'**NOT WORKING** This section is giving me the problem. I want to copy the value from the variable wks and paste into SPA_SummaryView.
    wks.Select
    Range("O1").Select
    Selection.Copy
    Range("O8").Select
    Sheets("SPA_SummaryVIEW").Select
    Range("C5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("C15").Select
    Columns("C:C").EntireColumn.AutoFit
    Range("C2").Select
Next
Unload Me

End Sub

I am using Excel 2010. Any help would be appreciated...
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
DOn't know from that. I usually do testing of objects before using them:
Code:
    Workbooks.Open fileName:=workOInFile
    Set wkOrdInWkBk = ActiveWorkbook
    
    If Not wkOrdInWkBk Is Nothing Then
        Set wkOrdInWkSht = wkOrdInWkBk.Sheets(1)
        If Not wkOrdInWkSht Is Nothing Then
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

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