Solved

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

Posted on 2007-11-28
9
206 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

760 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

19 Experts available now in Live!

Get 1:1 Help Now