Solved

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

Posted on 2007-11-28
9
216 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

632 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