Solved

Range(ColRow).Top does not return top corner of cell.

Posted on 2007-11-28
9
212 Views
Last Modified: 2013-12-25
Hi!

I have a loop that goes down a column and inserts drop downs per row.
It places each drop down in the upper left corner of the cell.
The drop downs start out aligned with the top of the cell, but progressively get more and more out of synch.

Any idea why that is the case?

Thanks.
0
Comment
Question by:DotTheBug
  • 5
  • 4
9 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 20366813
What is your code, and is there a reason you can't use data validation dropdowns?
0
 

Author Comment

by:DotTheBug
ID: 20366833
Hi rorya,

Below is the code. One thing to note is that I need to create these on the fly - the number and the value selected depend on results coming in from the db. Thanks.

            Do While Not rs.EOF
                For f = 0 To rs.Fields.Count - 4
                    .Cells(r, c + f) = rs.Fields(f).Value
                Next f
                Set Target = Range(OVERRIDE_CLASS_COL & r)
               
                Set ddBox = ActiveSheet.DropDowns.Add(Target.Left, Target.Top, 75, Target.Height)
                ddBox.AddItem "Yes"
                ddBox.AddItem "No"
                With ddBox
                    .ListFillRange = ""
                    .LinkedCell = ""
                    .DropDownLines = 8
                    '.Display3DShading = True
                    '.Value = 2
                    .Value = rs.Fields(f).Value
                End With
                Set Target = Range(LAST_COL & r)
                Set ddBox = ActiveSheet.DropDowns.Add(Target.Left, Target.Top, 75, Target.Height)
                ddBox.AddItem "Yes"
                ddBox.AddItem "No"
                With ddBox
                    .ListFillRange = ""
                    .LinkedCell = ""
                    .DropDownLines = 8
                    '.Display3DShading = True
                    '.Value = 2
                    .Value = rs.Fields(f + 2).Value
                End With
                r = r + 1
                recCnt = recCnt + 1
                rs.MoveNext
            Loop
0
 

Author Comment

by:DotTheBug
ID: 20366836

            Do While Not rs.EOF
                For f = 0 To rs.Fields.Count - 4
                    .Cells(r, c + f) = rs.Fields(f).Value
                Next f
                Set Target = Range(OVERRIDE_CLASS_COL & r)
                
                Set ddBox = ActiveSheet.DropDowns.Add(Target.Left, Target.Top, 75, Target.Height)
                ddBox.AddItem "Yes"
                ddBox.AddItem "No"
                With ddBox
                    .ListFillRange = ""
                    .LinkedCell = ""
                    .DropDownLines = 8
                    '.Display3DShading = True
                    '.Value = 2
                    .Value = rs.Fields(f).Value
                End With
                Set Target = Range(LAST_COL & r)
                Set ddBox = ActiveSheet.DropDowns.Add(Target.Left, Target.Top, 75, Target.Height)
                ddBox.AddItem "Yes"
                ddBox.AddItem "No"
                With ddBox
                    .ListFillRange = ""
                    .LinkedCell = ""
                    .DropDownLines = 8
                    '.Display3DShading = True
                    '.Value = 2
                    .Value = rs.Fields(f + 2).Value
                End With
                r = r + 1
                recCnt = recCnt + 1
                rs.MoveNext
            Loop

Open in new window

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 20366893
Works OK for me - which version of Excel are you using? (You could still use data validation for this incidentally)
Regards,
Rory
0
 

Author Comment

by:DotTheBug
ID: 20366950
Excel 2003. Drop down starts out aligned with the top left corner, then gets out of synch around the 5th iteration.

Thanks.
0
 

Author Comment

by:DotTheBug
ID: 20366956
Just to clarify, it is still placed related to the top left corner, problem is the few pixels out from the top.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 20367350
I'll have to test when I get home - tried your code (altering the loop slightly as I didn't have a recordset) and everything lined up nicely in XL2002. One thought - do you have a zoom setting other than 100%?
0
 

Author Comment

by:DotTheBug
ID: 20367415
The zoom setting was indeed the culprit. Once I switched it to 100% before adding the drop downs, they drop downs lined up nicely with the top of the cells for me as well. Thanks :)!
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 20368181
Glad to help.
Rory
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now