Toontown Friends! Forum Index
Home Forums Blogs Who's Online My Fansites The Fridge
  Forum Tour   Register 
Need Excel Help-Advanced

Goto page 1, 2, 3, 4  Next

 
This forum is locked: you cannot post, reply to, or edit topics.      This topic is locked: you cannot edit posts or make replies.    Toontown Friends! Forum Index -> TTF Lounge -> General Archive
Display posts from previous:   
Author Message
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Mon Aug 07, 2006 7:26 pm    Post subject:
Need Excel Help-Advanced
View Single PostView Single Post

Does anybody here know what the method is to move to a new cell relative to another cell in a procedure? (Meaning; given a certain cell, go down a set number of rows and over a set number of columns)

For illustrational purposes, below is the procedure minus the proper (read: easiest) way of doing it. The procedure works for what I need it to do but is dependant on knowing which column I want to be in when the procedure is done. Although it works, it is a roundabout way of getting where I need to be. Although I don't normally comment my code I did so here for the sake of ease of reading it for anybody who might be able to help.

Quote:

Sub NoTaxes()
Dim varTarget As Variant
Dim varTemp As Variant
Dim varTemp2 As Variant
Dim varTemp3 As Variant
Call temp408
varTemp = ActiveCell.Address 'store the current cell address in memory
varTemp2 = Mid(varTemp, 5) 'retrieve the rows from the above address
varTarget = "ad" & varTemp2 'assign the target address to a variable for c & p
Range("ah135:ai137").Select 'copy some custom formulas saved in the workbook
Selection.Copy 'load them into memory
Range(varTarget).Select 'move to the target cell
ActiveSheet.Paste 'paste the custom formulas
Range(varTemp).Activate 'um...I'm not sure why I take this side-trip. Embarassed
varTemp2 = varTemp2 + 5 'add 5 rows to the place where I pasted the custom formulas
varTemp3 = "aa" & varTemp2 'store the cell in column AA 5 rows down from the paste
Range(varTemp3).Activate 'move to the above set cell
'Call PrintMe
End Sub


If you can answer my question then you can see that the above procedure is 6-7 lines longer than it needs to be. My searches in help usually lead me either to Move which is not what I'm looking for or xlUp/xlToLeft/xlBlahBlahBlah and No help available for that. I know there is a method for moving relative to where you are but I cannot remember what it is and I'm apparently no good at coming up with a good enough search word. Sad

N.B. Although it's not showing up in the post, the plus sign is there in line 14 of the procedure. Confused

Thanks to anybody who can help and to anybody who tries. Smile

**Edit**Hmph, the plus sign shows up in the post but it did not in the preview.

Back to top
LeaWildcat
Daisy's Garden Toon
Daisy's Garden Toon


Age: 37
Joined: 13 Jun 2006
Posts: 292
Location: Texas
PostPosted: Mon Aug 07, 2006 8:08 pm    Post subject:

Is this the code from the record button? or one you wrote? If it's from one you wrote sometimes it's easier to use the record button and do the steps in the shortest moves possible and then look at the code. Also are you wanting to copy that information or move it, I'm a little confused.

Back to top
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Mon Aug 07, 2006 8:18 pm    Post subject:

I wrote it. The macro recorder will not declare variables.

I am wanting to copy the information since the procedure might be, and usually is, called multiple times.

Thanks for the suggestion and that was one of the first things I tried. Unfortunately what it records is the address of the target so if I called the procedure multiple times for multiple different targets it would return always to the one used in the recording. As I said, I need it relative to the target regardless of how many times it's called. Sad

Back to top
LeaWildcat
Daisy's Garden Toon
Daisy's Garden Toon


Age: 37
Joined: 13 Jun 2006
Posts: 292
Location: Texas
PostPosted: Mon Aug 07, 2006 8:51 pm    Post subject:

Would something like this help? I wrote this one for a spreadsheet at work. What it does is copy files from a certain point to another point on the sheet overwriting the formulas to adjust for the monthly readings. There are some other things involved but I'm thinking the scroll may be what you are looking for.

Quote:
TKNcopystd()
'
' TKNcopystd Macro
' Macro recorded 11/17/2005 by amy marie northam
'

'
Sheets("5ppm TKN").Select
ActiveWindow.LargeScroll ToRight:=-3
ActiveWindow.LargeScroll Down:=-1
Range("G5:G10").Select
Selection.Copy
Range("F5:F10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("C8").Select
Application.CutCopyMode = False
Selection.ClearContents
Sheets("10ppm TKN").Select
ActiveWindow.LargeScroll ToRight:=-3
ActiveWindow.LargeScroll Down:=-3
Range("G5:G10").Select
Selection.Copy
Range("F5:F10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("C7").Select
Application.CutCopyMode = False
Selection.ClearContents
Sheets("1ppm TKN").Select
Range("G5:G10").Select
Selection.Copy
Range("F5:F10").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("C55:G55").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.LargeScroll Down:=-3
ActiveWindow.SmallScroll Down:=2
Range("C15").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C7").Select
Application.CutCopyMode = False
Selection.ClearContents
End Sub

Back to top
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Mon Aug 07, 2006 9:12 pm    Post subject:

LeaWildcat :
Would something like this help? I wrote this one for a spreadsheet at work. What it does is copy files from a certain point to another point on the sheet overwriting the formulas to adjust for the monthly readings. There are some other things involved but I'm thinking the scroll may be what you are looking for.

Quote:
TKNcopystd()
ActiveWindow.LargeScroll ToRight:=-3
ActiveWindow.LargeScroll Down:=-3
End Sub


Interesting...I changed that to read
Quote:

ActiveWindow.SmallScroll ToRight:=1
ActiveWindow.SmallScroll Down:=1


and although it changed the view to have B2 as the upper-left most cell (as would be expected) it maintained A1 as the active cell. Sad

Thanks for the idea though. Smile

Back to top
LeaWildcat
Daisy's Garden Toon
Daisy's Garden Toon


Age: 37
Joined: 13 Jun 2006
Posts: 292
Location: Texas
PostPosted: Mon Aug 07, 2006 9:47 pm    Post subject:

Quote:
varTemp2 = Mid(varTemp, 5) 'retrieve the rows from the above address

can you save a step by saying varTemp2 = Mid(varTemp, 5) + 5?

Also this seems redundant, like you are assigning it twice.
Quote:
varTemp2 = Mid(varTemp, 5) 'retrieve the rows from the above address
varTarget = "ad" & varTemp2 'assign the target address to a variable for c & p

and

Range(varTemp).Activate 'um...I'm not sure why I take this side-trip.
varTemp2 = varTemp2 + 5 'add 5 rows to the place where I pasted the custom formulas
varTemp3 = "aa" & varTemp2 'store the cell in column AA 5 rows down from the paste
Range(varTemp3).Activate 'move to the above set cell

Back to top
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Mon Aug 07, 2006 10:11 pm    Post subject:

LeaWildcat :
Quote:
varTemp2 = Mid(varTemp, 5) 'retrieve the rows from the above address

can you save a step by saying varTemp2 = Mid(varTemp, 5) + 5?


Not really. I need to do something at cell Range(AD & Whatever the current row is). I only need to add the 5 rows after it's pasted to the current row.

Quote:
Also this seems redundant, like you are assigning it twice.
Quote:
varTemp2 = Mid(varTemp, 5) 'retrieve the rows from the above address
varTarget = "ad" & varTemp2 'assign the target address to a variable for c & p

and

Range(varTemp).Activate 'um...I'm not sure why I take this side-trip.
varTemp2 = varTemp2 + 5 'add 5 rows to the place where I pasted the custom formulas
varTemp3 = "aa" & varTemp2 'store the cell in column AA 5 rows down from the paste
Range(varTemp3).Activate 'move to the above set cell


I'm only changing the value of varTemp2 after I've done the pasting and am ready to move on where I may call the procedure again.

It may seem redundant but trust me it's not. Smile The only thing I can't figure out why I did something there is activating Range(varTemp). I'm sure it was important to something at some point but it's definitely doing nothing now.

There is an issue with a superfluous variable that is resolved if I did need to return to Range(varTemp) at some point. Again, I can't see what that was and I wrote this so long ago I can't remember what it was now. Sad

I do appreciate your help though. Smile

Back to top
Calamity
I don't jump out of airplanes.


Age: 36
Joined: 21 Mar 2006
Posts: 399
Location: I'll get you my pretty and your little dog too!
PostPosted: Mon Aug 07, 2006 11:36 pm    Post subject:

Throw a birthday cake at it and call it a day Shocked my brain hurts shaking

Back to top
chocoholic1415
Give me chocolate and no one gets hurt!


Age: 39
Joined: 03 Dec 2005
Posts: 1813
Location: CT
PostPosted: Tue Aug 08, 2006 1:02 am    Post subject:

um, why do you need to move to the cell to paste the info?

Range(varTarget).Select
ActiveSheet.Paste


can be replaced with:

Range(varTarget).Paste

No need to actually select the cell you want to paste to when you are using VBA.

also, if you want to paste something a certain distance from a given cell, the command you probably want to use is the offset command and/or the cells command. It's really late here and i'm not sure what the objective is. I'll check back in the morning or feel free to prill me.

Back to top
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Tue Aug 08, 2006 1:59 am    Post subject:

chocoholic1415 :
um, why do you need to move to the cell to paste the info?

Range(varTarget).Select
ActiveSheet.Paste


can be replaced with:

Range(varTarget).Paste

No need to actually select the cell you want to paste to when you are using VBA.

also, if you want to paste something a certain distance from a given cell, the command you probably want to use is the offset command and/or the cells command. It's really late here and i'm not sure what the objective is. I'll check back in the morning or feel free to prill me.


LoL, thanks a million! Exactly: Activecell.Offset(rows, cols) Smile

About the pasting without "being there". Logically you should be able to do that but for some reason I cannot make it do that. It doesn't give me a logical error which I'd expect and intellisense uppercases the P but it does produce a runtime error. Confused

Quote:
Sub testme()
Range("b3").Select
Debug.Print Selection
Range("b1").Paste
End Sub


The value, well text as I tested it, is properly loaded into memory and prints to the Immediate window but it crashes on line 3. Maybe I missed something? Sad

Interestingly, and not really what I expected, if there is a formula in cell B3 (in this example) it returns the value of the formula and not the formula itself.

Back to top
Granny MoMo
Betty Ruth
Betty Ruth


Age: 38
Joined: 26 Oct 2005
Posts: 5449
Location: Singing Numa Numa... Clown Pen UP! Oh, look! A quarter!! Looking for the Doughnut shop...
PostPosted: Tue Aug 08, 2006 8:08 am    Post subject:

*picks up + sign* Here's your sign!

Back to top
chocoholic1415
Give me chocolate and no one gets hurt!


Age: 39
Joined: 03 Dec 2005
Posts: 1813
Location: CT
PostPosted: Tue Aug 08, 2006 8:28 am    Post subject:

Rubberboots :

LoL, thanks a million! Exactly: Activecell.Offset(rows, cols) Smile

About the pasting without "being there". Logically you should be able to do that but for some reason I cannot make it do that. It doesn't give me a logical error which I'd expect and intellisense uppercases the P but it does produce a runtime error. Confused

Quote:
Sub testme()
Range("b3").Select
Debug.Print Selection
Range("b1").Paste
End Sub


The value, well text as I tested it, is properly loaded into memory and prints to the Immediate window but it crashes on line 3. Maybe I missed something? Sad

Interestingly, and not really what I expected, if there is a formula in cell B3 (in this example) it returns the value of the formula and not the formula itself.


The debug.print command will paste the value of the cell, but the command itself should paste the forumula.
Sub testme()
Range("b3").Copy
Range("b1").Paste
End Sub

will copy the formula from cell b3 and paste it into cell b1.

Glad you looked up the offset function, it's definitely one of the more useful functions.

Back to top
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Tue Aug 08, 2006 8:34 pm    Post subject:

chocoholic1415 :

The debug.print command will paste the value of the cell, but the command itself should paste the forumula.
Sub testme()
Range("b3").Copy
Range("b1").Paste
End Sub

will copy the formula from cell b3 and paste it into cell b1.

Glad you looked up the offset function, it's definitely one of the more useful functions.


Owoooo!! It still crashes with range().paste. If I use .PasteSpecial though... Rolling Eyes I'll leave it to MS to rationalize that one. Neutral

Correct me if I'm wrong but you cannot in VBA define a custom method, right? Of course you can in VB but I seem to recall that you cannot in VBA.

Thanks a million! Not only did you help with what I needed but also with something that I'd just learned to live with, although it did bother me that I had to do that extra step. Smile

Back to top
Nanner
Punctuation Police


Age: 48
Joined: 21 Nov 2005
Posts: 3900
Location: Anyone find my salt yet?
PostPosted: Tue Aug 08, 2006 10:42 pm    Post subject:

You mean excel isn't just for making grocery lists on?

BTW what language are you all speaking? It isn't english!!!!!!!!!!

Back to top
LeaWildcat
Daisy's Garden Toon
Daisy's Garden Toon


Age: 37
Joined: 13 Jun 2006
Posts: 292
Location: Texas
PostPosted: Tue Aug 08, 2006 11:13 pm    Post subject:

LOL that's an excellent use nanner Wink

*Doing the I'm not worthy bow to choc and Rubber

I thought I was pretty profecient.

Back to top
chocoholic1415
Give me chocolate and no one gets hurt!


Age: 39
Joined: 03 Dec 2005
Posts: 1813
Location: CT
PostPosted: Wed Aug 09, 2006 1:03 am    Post subject:

Nanner, what are u doing in the tech support section?

Quote:
Owoooo!! It still crashes with range().paste. If I use .PasteSpecial though... Rolling Eyes I'll leave it to MS to rationalize that one. Neutral


what version are you using? I've always wrote it that way. 2003 (that's what I'm on now) seems to be pickier with syntax than earlier versions. Earlier versions you could even leave off the "Range" and just use [B2].Paste instead of Range("B2").Paste. That syntax still works for me in some intances, but not in others - go figure Rolling Eyes


Quote:
Correct me if I'm wrong but you cannot in VBA define a custom method, right? Of course you can in VB but I seem to recall that you cannot in VBA.


Never say never. You can make it do whatever you need it to with a little creativity Smile

Back to top
Granny MoMo
Betty Ruth
Betty Ruth


Age: 38
Joined: 26 Oct 2005
Posts: 5449
Location: Singing Numa Numa... Clown Pen UP! Oh, look! A quarter!! Looking for the Doughnut shop...
PostPosted: Wed Aug 09, 2006 8:00 am    Post subject:

chocoholic1415 :
Nanner, what are u doing in the tech support section? Smile


Nanner, hon, this isn't the doughnut shop. *grabs the wee ducky's wing* C'mon, I'll take you back where you belong!

Back to top
Rubberboots
Rubberbootsian


Age: 43
Joined: 25 May 2006
Posts: 185
PostPosted: Wed Aug 09, 2006 10:54 am    Post subject:

chocoholic1415 :
what version are you using? I've always wrote it that way. 2003 (that's what I'm on now) seems to be pickier with syntax than earlier versions. Earlier versions you could even leave off the "Range" and just use [B2].Paste instead of Range("B2").Paste. That syntax still works for me in some intances, but not in others - go figure Rolling Eyes


I'm using 2000 and 2002. Yeah, I tend to write all my code the long way and avoid shortcuts. I don't know why, I just do. (I also force variable declaration Embarassed) LoL, it probably comes from writing a lot of bum code and having to debug it so I just write it the long way first. Confused

Anyway, thanks again for your help! Smile

Back to top
Nanner
Punctuation Police


Age: 48
Joined: 21 Nov 2005
Posts: 3900
Location: Anyone find my salt yet?
PostPosted: Wed Aug 09, 2006 11:21 am    Post subject:

HEY! I can fix a puter, install stuff, make a webpage, fix pictures etc etc. Just never used Excel and Word to their full extent! Did take some classes paid for by the place I use to work but of course never paid attention Very Happy Then again it wasn't THIS complicated! Now I have no need for it (Not like I really did back then either)

Ummm I don't LIKE donuts really......can I have some ice cream?


Oh and I came here thinking I might learn something......but it's wayyyy over my little bitty ducky head! (and that thingy about not ever having a use for the info) Soooo...... Razz


Have 2 major puter geeks in the family....don't need to learn the complicated stuff!!!!!

Back to top
Loopy
Passing out cookies


Age: 38
Joined: 13 Oct 2005
Posts: 2544
PostPosted: Wed Aug 09, 2006 11:25 am    Post subject:

ROFL! I totally feel like I entered another country with this post.

Back to top
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.      This topic is locked: you cannot edit posts or make replies.  Quick Reply    Toontown Friends! Forum Index -> TTF Lounge -> General Archive All times are GMT - 4 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 




Powered by phpBB © 2001, 2005 phpBB Group

Server Uptime: 85 days 21 hours 05 minutes | Average Load: 2.65, 1.85, 1.13


All Toontown images on this site are © Disney Inc., All Rights Reserved. Toontownfriends.com is a fan site and not affiliated with Disney Inc.
All other trademarks and copyrights on this page are owned by their respective owners, with no infringement intended. Comments are owned by the Poster. The Rest © 2005-2007 Brady Bowen