|
|
|
| Author |
Message |
Rubberboots Rubberbootsian
Age: 43 Joined: 25 May 2006 Posts: 186
|
Posted: Mon Aug 07, 2006 7:26 pm Post subject: |
|
|
|
|
|
| Back to top |
|
 |
|
|
LeaWildcat Daisy's Garden Toon


Age: 37 Joined: 13 Jun 2006 Posts: 292 Location: Texas
|
Posted: 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: 186
|
Posted: 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. 
|
|
| Back to top |
|
 |
LeaWildcat Daisy's Garden Toon


Age: 37 Joined: 13 Jun 2006 Posts: 292 Location: Texas
|
Posted: 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: 186
|
Posted: 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.
Thanks for the idea though. 
|
|
| Back to top |
|
 |
LeaWildcat Daisy's Garden Toon


Age: 37 Joined: 13 Jun 2006 Posts: 292 Location: Texas
|
Posted: 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: 186
|
Posted: 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. 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.
I do appreciate your help though. 
|
|
| 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!
|
Posted: Mon Aug 07, 2006 11:36 pm Post subject: |
|
|
|
Throw a birthday cake at it and call it a day  my brain hurts 
|
|
| Back to top |
|
 |
chocoholic1415 Give me chocolate and no one gets hurt!

Age: 39 Joined: 03 Dec 2005 Posts: 1813 Location: CT
|
Posted: 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: 186
|
Posted: 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)
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.
| 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?
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


Age: 38 Joined: 26 Oct 2005 Posts: 5449 Location: Singing Numa Numa... Clown Pen UP! Oh, look! A quarter!! Looking for the Doughnut shop...
|
Posted: 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
|
Posted: Tue Aug 08, 2006 8:28 am Post subject: |
|
|
|
| Rubberboots : |
LoL, thanks a million! Exactly: Activecell.Offset(rows, cols)
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.
| 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?
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: 186
|
Posted: 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... I'll leave it to MS to rationalize that one.
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. 
|
|
| Back to top |
|
 |
Nanner Punctuation Police

Age: 48 Joined: 21 Nov 2005 Posts: 3902 Location: Anyone find my salt yet?
|
Posted: 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


Age: 37 Joined: 13 Jun 2006 Posts: 292 Location: Texas
|
Posted: Tue Aug 08, 2006 11:13 pm Post subject: |
|
|
|
LOL that's an excellent use nanner
*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
|
Posted: Wed Aug 09, 2006 1:03 am Post subject: |
|
|
|
|
|
| Back to top |
|
 |
Granny MoMo 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...
|
Posted: Wed Aug 09, 2006 8:00 am Post subject: |
|
|
|
| chocoholic1415 : | Nanner, what are u doing in the tech support section?  |
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: 186
|
Posted: 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
|
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 ) 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.
Anyway, thanks again for your help! 
|
|
| Back to top |
|
 |
Nanner Punctuation Police

Age: 48 Joined: 21 Nov 2005 Posts: 3902 Location: Anyone find my salt yet?
|
Posted: 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  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......
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
|
Posted: Wed Aug 09, 2006 11:25 am Post subject: |
|
|
|
ROFL! I totally feel like I entered another country with this post.
|
|
| Back to top |
|
 |
|
|
|