Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activecell offset without select 2

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
I have code that has to place notes in sequence from left to right. Column L holds the list of numbers to be pulled from the systme. Previously it was written as

i = 2

Do
' Get the number
sNumber = Range("L" & i).Select

' SQL Code goes here

' Used as a rolling variable with the activecell offset command
' to go to the right and enter existing notes
k = 3

While Not rsERDB.EOF

' Put the note into the correct cell
ActiveCell.Offset(0, k).Value = New_Note

' Move the offset to the right by one cell
k = k + 1

' Go to the next record in SQL
rsERDB.MoveNext

Wend

Loop

I don't know how but would like to offest to the right without using the select.

Anyone know how to do that?
 
Replace this:
ActiveCell.Offset(0, k).Value = New_Note
with this:
Cells(i + k, "L").Value = New_Note

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 


hi,

I avoid using the Select and Activate method, unless the situation call for it...
Code:
i = 2

Do
    ' Get the number
    sNumber = [b]Cells(i, "L").Value[/v]
     
    ' SQL Code goes here

    ' Used as a rolling variable with the activecell offset command
    ' to go to the right and enter existing notes
    k = 3
    
    While Not rsERDB.EOF

        ' Put the note into the correct cell
        [b]Cells(i, "L")[/b].Offset(0, k).Value = New_Note
        
        ' Move the offset to the right by one cell
        k = k + 1

        ' Go to the next record in SQL
        rsERDB.MoveNext
      
    Wend

Loop

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
OOps, sorry for the typo:
Replace this:
ActiveCell.Offset(0, k).Value = New_Note
with this:
Cells(i, 12 + k).Value = New_Note

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks guys - both ways work.

Skip - I totally agree and have been re-writing code to avoid select or activate. Code runs faster, the screen doesn't flash and it helps reduce user errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top