macro to paste value unhidden columns

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have the following code below to copy and paste data on certain sheets as follows


I would like the code amended so that only the data on the undidden columns are copied and pasted as values

Your assistance is most appreciated

Sub ValueCopyCommSheets()


Dim i As Long
For i = Sheets("BTCON").Index To Sheets("BRDA East").Index
Unhide_All_Columns_in_Workbook
With Sheets(i)
' If .Visible Then
.UsedRange.Copy

.UsedRange.PasteSpecial Paste:=xlPasteValues


End With
Next i

End Sub
Code:
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi
Try
VBA Code:
Sub ValueCopyCommSheets()
Dim i As Long
For i = Sheets("BTCON").Index To Sheets("BRDA East").Index
With Sheets(i)
If .Visible Then
With .UsedRange
.Value = .Value
End With
Else
.Visible = True
End If
End With
Next i
End Sub
 
Upvote 0
Hi howard,

not so certain about the requirement (this code will exclude hidden sheets) so maybe

VBA Code:
Sub ValueCopyCommSheetsVisibleRange()
' https://www.mrexcel.com/board/threads/macro-to-paste-value-unhidden-columns.1222670/
Dim i           As Long
Dim rngArea     As Range

For i = Worksheets("BTCON").Index To Worksheets("BRDA East").Index
'  Unhide_All_Columns_in_Workbook
  With Worksheets(i)
    If .Visible Then
      For Each rngArea In .UsedRange.SpecialCells(xlCellTypeVisible).Columns
        rngArea.Value = rngArea.Value
      Next rngArea
    End If
  End With
Next i

End Sub

Ciao,
Holger
 
Upvote 0
Solution
Many Thanks forgthe help. Code works perfectly
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

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