Is there a way of pasting an array into a different workbook, while skipping Hidden Columns

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Hello guys, I have the following code, which I use to fill and then paste my array. This go around, I'm trying to paste the values into a worksheet("Upload Template") which is in another workbook. This specific worksheet has a lot of columns hidden. Is there a way I can make this code paste the data into the visible cells only?

VBA Code:
Sub Testing()
Dim lr&, GL

lr = Range("A:R").SpecialCells(xlCellTypeLastCell).Row

GL = Range("A1:R" & lr).Value

Workbooks("Upload Template.xlsm").Activate

Range("E9").Resize(UBound(GL), UBound(GL, 2)).Value = GL


End Sub

Thank you.
 
Hi Coyotex3,
So give the following one a try.

VBA Code:
Sub Sample2()
    Dim GL, x As Long, y As Long, z As Long
    GL = Range("A1:R" & Range("A:R").SpecialCells(xlCellTypeLastCell).Row).Value
    Workbooks("Upload Template.xlsm").Activate
    With Range("E9")
        Do
            If .Offset(z).EntireRow.Hidden = False Then
                x = x + 1
                For y = LBound(GL, 2) To UBound(GL, 2)
                    .Cells(z + 1, y).Value = GL(x, y)
                Next
            End If
            z = z + 1
        Loop Until x = UBound(GL)
    End With
End Sub
@Colo San, I tried this one and this one is pasting the array into the hidden columns for some reason.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Sorry, the code that I made was for hidden "Rows". I messed up again! ;)
Haha no worries! Alex modification happened to work and was able to do what I needed :)! My job is partially automated at the moment thanks to you guys!

Arigatou Gozaimasu, Okiniawa ni modoritai desu!
 
Upvote 0
I went ahead and marked Alex's reply as the solution. Here is the code with the one modification:
VBA Code:
Sub CopyToVisibleColumns()

Dim wbGL As Workbook, wbTemplate As Workbook
Dim shtGL As Worksheet, shtTemplate As Worksheet
Dim lrGL As Long, colGL As Long
Dim rngGL As Range, cellTemplate As Range
Dim arrGL As Variant
   
Application.ScreenUpdating = False
   
Set wbGL = ThisWorkbook
Set shtGL = wbGL.ActiveSheet
Set rngGL = shtGL.Range("A:R")
lrGL = rngGL.Find(What:="*" _
, Lookat:=xlPart _
, LookIn:=xlValues _
, searchorder:=xlByRows _
, searchdirection:=xlPrevious).Row
Set rngGL = rngGL.Resize(lrGL - 1).Offset(1)
arrGL = rngGL
   
Set wbTemplate = workbooks("Upload Template.xlsm")
Set shtTemplate = wbTemplate.Worksheets(1)
Set cellTemplate = shtTemplate.Range("E9").Resize(rngGL.Rows.Count)
   
For colGL = 1 To UBound(arrGL, 2)
       
Do Until Not cellTemplate.EntireColumn.Hidden
Set cellTemplate = cellTemplate.Offset(0, 1)
Loop
       
cellTemplate.Value = Application.Index(arrGL, 0, colGL)
Set cellTemplate = cellTemplate.Offset(0, 1)
       
 Next colGL

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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