VBA to copy and paste as values

nirvehex

Well-known Member
Joined
Jul 27, 2011
Messages
505
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Looking for any help with the following code:

I'm trying to have the VBA select cell CX3 and down to the last row with values in this column and paste as values. I'm trying to add it into the code I have below so it does it at the end. Any ideas for a simple line of code? I'm feeling a bit brain dead at the moment. Thank you!

Code:
Sub SetupDetailsTab()


'1. Select Pivot, Select B4, control+shift down, count filled rows, store count


Dim NumberofRows As Long
Dim MyUnique As Object, c As Range

Application.ScreenUpdating = False

Sheets("Pivot").Select
Range("B4").Select
Range(Selection, Selection.End(xlDown)).Select


NumberofRows = Selection.Count


'2. Select Details, Select row 3, insert count + 2 down, copy formulas from row 3 down to fourth row from bottom


Sheets("Details").Select
Rows("4:4").Select
Rows("4:" & NumberofRows + 2).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove


Range("A3:DC3").Select
Selection.AutoFill Destination:=Range("A3:DC" & NumberofRows + 2), Type:=xlFillDefault



'3. Select Pivot, Select B4, copy over to F4 and down to last row, select details tab and paste starting in B2

Sheets("Pivot").Select
    Range("B4").Select
        Range(Selection, Cells(Selection.End(xlDown).Row, Selection.End(xlToRight).Column - 1)).Select
        Selection.Copy
    Sheets("Details").Select
        Range("B3").Select
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
            xlNone, SkipBlanks:=False, Transpose:=False
            
Set MyUnique = CreateObject("Scripting.Dictionary")

Sheets("Details").Select
Range("B3").Select
Range(Selection, Selection.End(xlDown)).Select

For Each c In Selection
        If c.EntireRow.Hidden = False Then MyUnique(CStr(c)) = 1
    Next c

With ActiveSheet
Range("B3").Select
Selection.End(xlDown).Select
Selection.Offset(2, 0).Select

End With

Selection.Value = MyUnique.Count

Set MyUnique = Nothing

Cells.Select
    Cells.EntireColumn.AutoFit

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Nevermind, I figured this out.

Code:
Sheets("Details").Columns("CX").Copy
Sheets("Details").Columns("CX").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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