Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-28
9
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

705 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