Solved

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

Posted on 2007-11-28
9
215 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

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!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

734 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