Avatar of Stephen Byrom
Stephen Byrom
Flag for Ireland asked on

Declaring variables

I'm having trouble with my declarations I think.
I can never decide if it should be a Long or Range or Cell etc etc.

I am struggling to get the attached code working as I keep getting "application defined or object defined error", which I presume means I got it wrong again regarding my declarations.  

As always any pointers are greatly appreciated, and maybe someone could point me in the right direction of any articles helping me understand Excel VBA declarations.

Thanks
Dim x As Range
Dim ws As Worksheet
Dim lr As Long
Set ws = ThisWorkbook.Sheets("Data")

lr = ws.Range("T1048576").End(xlUp).Row
    For Each x In ws.Range("T3:T" & lr).Cells
        If x.Value <> 0 Then
            ws.Range("AL1048576").End(xlUp).Offset(1).vlaue = x.Offset(1).Value
        End If
    Next x

Open in new window


I have tried a number of variations of the Range,Cell,Long etc etc to no avail.
Microsoft Excel

Avatar of undefined
Last Comment
Stephen Byrom

8/22/2022 - Mon
SOLUTION
Alex [***Alex140181***]

THIS SOLUTION 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
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Saqib Husain

It looks ok to me. Which line are you getting the error?
ASKER CERTIFIED SOLUTION
Rory Archibald

THIS SOLUTION 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
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Saqib Husain

THIS SOLUTION 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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rory Archibald

I know - hence my follow-up questions. :)
Stephen Byrom

ASKER
Sorry, I had to step out for a while......

I've been developing this workbook for some time now and I am starting to miss the obvious. Thanks rorya, and thanks to the rest for taking the time to comment.

regarding attaching the workbook for better clarity;
I have the slowest of connection speeds :( and attaching the file would have probably taken a week. (rural Ireland is not hot on technology) :)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes