Thread: [Solved] Sorting Challenge
View Single Post
 
Old 06-21-2012, 01:54 PM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default

Okay, you've slightly misunderstood my quesiton. Let me explain what I was driving at....

In my example I used
Code:
With Sheet1
Sheet1 is the codename of the worksheet in the attachment you gave in post #1. So my code is doing stuff with Sheet1. It understands what Sheet1 is so the code runs fine.

In your code you used this instead:
Code:
   With Data
Data isn't anything - it's just a word (a variable) which you've put in your code. You're getting an error message because it doesn't know what Data is. Your code needs to explain which worksheet the sort should be happening on. To put it slightly more technically: you don't have variable declaration enforced (with an Option Explicit statement) so when the compiler scans your code it creates a Variant variable called Data with holds a value of Empty.


So you need to either use the worksheet's codename like I did (you can see the codename in the VBA IDE in the project explorer window - see my attachment) or you need to get a reference to the worksheet via the Worksheets collection using either the worksheet's name or it's index (eg With Worksheets("Data"). Does that make sense?
Attached Images
File Type: jpg Codename vs Name.jpg (84.3 KB, 12 views)
__________________
Colin

RAD Excel Blog
Reply With Quote