Link to home
Start Free TrialLog in
Avatar of Flora Edwards
Flora EdwardsFlag for Sweden

asked on

VBA modification help needed from earlier solution (VBA to modification to take it from table instead of sheet)

I had this question after viewing VBA to modification to take it from table instead of sheet.

How can i modify the code in my earlier question, that if  the source worksheet has a table then take data from table
    'Copy Data From Source Workbook
    Set SourceWs = SourceWB.Sheets(1)
    Set CopyRng = SourceWs.ListObjects(1).Range  

Open in new window


If sheets(1) does not have a table then use the code below

   Set SourceWs = SourceWB.Sheets(1)
    SourceLR = SourceWs.Range("A2").SpecialCells(xlCellTypeLastCell).Row
    SourceLC = SourceWs.Range("A2").SpecialCells(xlCellTypeLastCell).Column
    Set CopyRng = SourceWs.Range(SourceWs.Range("A2"), SourceWs.Cells(SourceLR, SourceLC))

Open in new window

SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Flora Edwards

ASKER

Thank you very much Rgonzo1971 and Norie.

very much appreciated!    you guys saved me a lot of time.   it is really magical. i am so happy!
Dear Norie and Rgonzo1971

somehow the ListObject(1).Range does not work. i posted a new question here https://www.experts-exchange.com/questions/29070714/VBA-Import-frm-TBL-does-not-work-earlier-helped-by-Norie-and-Rgonzo1971.html
Avatar of Norie
Norie

Flora


How does it not work?
Thanks Norie.

it works now. it did not work because there was a hidden sheet.