troubleshooting Question

excel vba defining range with specialcells

Avatar of Lambel
Lambel asked on
Microsoft Excel
2 Comments1 Solution689 ViewsLast Modified:
I am building a procedure that creates a new workbook, looks up excel input files and copies/formats them in the new workbook.  I want make my code dynamic so it can adjust to varying cell ranges to copy and paste.  

In my attached code, line 330, I would like to replace "A834" with a dynamic reference to the cell.
How can I do this?

'copy whole sheet
    Sheets("OH Count Collateral").Select
    Cells.Select
    Selection.Copy
    
    'paste in OH Count sheet
    Sheets("OH Count").Select
    Range("A1").Select
    ActiveSheet.Paste
    
    'figure out where the data ends for the next paste
    Range("A1").Select
    Selection.End(xlDown).Select
    Range("A834").Select
    
    'copy the next sheet
    Sheets("OH Count Pool").Select
    Range("A1").Select
    ' use the SpecialCells method to select only cells with data
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Application.CutCopyMode = False
    Selection.Copy
    
    'paste into OH Count below the data from the first copy/paste
    Sheets("OH Count").Select
    ActiveSheet.Paste

Open in new window

ASKER CERTIFIED SOLUTION
Tracy
VBA Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros