Avatar of Lambel
Lambel

asked on 

excel vba defining range with specialcells

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

Microsoft Excel

Avatar of undefined
Last Comment
Lambel
ASKER CERTIFIED SOLUTION
Avatar of Tracy
Tracy
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Lambel
Lambel

ASKER

Thanks that works first time!
Lynn
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo