Attempting to set column value=column value on another sheet with only visible cells VBA

sax2play

Board Regular
Joined
Mar 13, 2021
Messages
63
Office Version
  1. 2016
Platform
  1. Windows
Hello Experts!

I am attempting to move data from one sheet to another without select/copy/paste due to the amount of data. I first filter the worksheet and then set range.value of new sheet = range.value of original sheet; however, I cannot get it to move only the visible cells. Thoughts??

VBA Code:
last_row2 = shEB.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count
    last_col2 = shEB.AutoFilter.Range.Rows(1).SpecialCells(xlCellTypeVisible).Cells.Count
    
    'Reformat/Move columns to new Easel Board Review Sheet
    Do While WB.Sheets("Config_Review").Cells(includedCol, 1) <> ""
    
        If WB.Sheets("Config_Review").Cells(includedCol, 1) = "" Then
            Set rngFound = WB.Sheets("EaselBoard_1").Range("1:1").Find(What:=WB.Sheets("Config_Review").Cells(includedCol, 1), LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=True)
        Else
            colString = WB.Sheets("Config_Review").Cells(includedCol, 1)
            Set rngFound = shEB.Range("1:1").Find(What:=colString, LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=True)
        End If
                
        If Not rngFound Is Nothing Then
            shNewEB.Range(shNewEB.Cells(1, 1), shNewEB.Cells(last_row2, last_col2)).SpecialCells (xlCellTypeVisible)
            shNewEB.Range(shNewEB.Cells(1, Col), shNewEB.Cells(last_row2, Col)).Value = shEB.Range(shEB.Cells(1, rngFound.Column), shEB.Cells(last_row2, rngFound.Column)).Value
            
        Else
            If colString = "" Then
                MsgBox "Cannot find column: " & WB.Sheets("Config_Review").Cells(includedCol, 1)
                End
            Else
                MsgBox "Cannot find column matching: " & colString
                
            End If
            
            Col = Col - 1
                       
        End If
        
        Col = Col + 1
        includedCol = includedCol + 1
        
    Loop

Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I am attempting to move data from one sheet to another without select/copy/paste due to the amount of data. I first filter the worksheet and then set range.value of new sheet = range.value of original sheet; however, I cannot get it to move only the visible cells. Thoughts??
You say move twice, but I assume you mean copy?

And it's not clear why you want to adopt this approach. Won't it be less efficient than a simple Filter and Copy/Paste?
 
Upvote 0
Solution
You say move twice, but I assume you mean copy?

And it's not clear why you want to adopt this approach. Won't it be less efficient than a simple Filter and Copy/Paste?
In my original macro, I copy and pasted the data (30k+ rows, 100+ columns) and it took 45 minutes. I changed it to set column new.value = column original.value and it dropped the time down to under 4 minutes, which was why I wanted to move the data. However, now that I changed the macro again to be dynamic and using loops, I was able to use range.copy and set destination and it is working well with no additional time.
 
Upvote 0
I changed the problem line above to:

VBA Code:
If Not rngFound Is Nothing Then
            shEB.Range(shEB.Cells(1, rngFound.Column), shEB.Cells(last_row, rngFound.Column)).SpecialCells(xlCellTypeVisible).Copy _
                Destination:=shNewEB.Range(shNewEB.Cells(1, Col), shNewEB.Cells(last_row, Col))

Which resolved the error.

Thanks for the help StephenCrump!
 
Upvote 0
No problem, it was just a point in the right direction.

I'm glad you got your code working, and presumably it's very fast now.
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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