Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 2nd, 2003, 11:35 AM
allmad allmad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 allmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 sec
Reputation Power: 0
adding to code

How do you add to this code so next time it will incert and copy the next row down.


Private Sub CommandButton2_Click()
Rows("24:24").Select
Selection.Insert Shift:=xlDown
Range("B25:F25").Select
Selection.Copy
Range("B24").Select
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub

so some how it would be


Private Sub CommandButton2_Click()
Rows("25:25").Select
Selection.Insert Shift:=xlDown
Range("B26:F26").Select
Selection.Copy
Range("B25").Select
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub

Reply With Quote
  #2  
Old August 2nd, 2003, 01:56 PM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
try this untested code:

at the top do:

Code:
dir varindex as integer
dir varindex2 as integer
dir rangea as string
dir rangeb as string
dir rangec as string


then:

Code:
Private Sub Form_Load()
 varindex = 1
End Sub

Private Sub CommandButton2_Click() 
varindex2 = varindex + 1
Rows("varindex:varindex").Select 
Selection.Insert Shift:=xlDown 
rangea = "B" & varindex2
rangeb = "F" & varindex2
Range("rangea:rangeb").Select 
Selection.Copy
rangec = "B" & varindex
Range("rangec").Select 
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone, _ 
SkipBlanks:=False, Transpose:=False 
varindex=varindex + 1
End Sub 


btw, that will start at row 1 - change:

Private Sub Form_Load()
varindex = 1
End Sub

to reflect your starting row (24?)
__________________

Last edited by computer : August 2nd, 2003 at 01:58 PM.

Reply With Quote
  #3  
Old August 3rd, 2003, 05:29 AM
allmad allmad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 allmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 sec
Reputation Power: 0
Thx, trying to get it working.

When I insert the following code

dir varindex as integer
dir varindex2 as integer
dir rangea as string
dir rangeb as string
dir rangec as string

it comes up in red and when u run it , it comes up with error. I know ive got to put the values in but where?, and how are thay writen? ( very very much a beginner) :-).

Thanx for your help

Mark

Reply With Quote
  #4  
Old August 3rd, 2003, 07:21 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
Code:
dir varindex as integer
dir varindex2 as integer
dir rangea as string
dir rangeb as string
dir rangec as string


must go at the VERY TOP of your form's module (I am assuming you are using VBA?), they go before any other subs or anthing unless there are already some there in which case put them at the end of the others.

Then paste in this bit:

Code:
Private Sub Form_Load()
 varindex = 1
End Sub

Private Sub CommandButton2_Click() 
varindex2 = varindex + 1
Rows("varindex:varindex").Select 
Selection.Insert Shift:=xlDown 
rangea = "B" & varindex2
rangeb = "F" & varindex2
Range("rangea:rangeb").Select 
Selection.Copy
rangec = "B" & varindex
Range("rangec").Select 
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone, _ 
SkipBlanks:=False, Transpose:=False 
varindex=varindex + 1
End Sub 


When you load the form, it will set the CommandButton2 sub to start its selecting and moving at row 1, to make it start at a different row, change varindex = 1 in the form_load sub to reflect the number of the row to start at.

Then when you run it, each time you click the button, it should move down each row.

Hope that helps,
computer

Reply With Quote
  #5  
Old August 4th, 2003, 03:00 AM
allmad allmad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 allmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 sec
Reputation Power: 0
Nope still doesnt work but. Ive enclose a pic of what im doing.
Attached Images
File Type: jpg code error.jpg (52.4 KB, 127 views)

Reply With Quote
  #6  
Old August 4th, 2003, 03:38 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
sorry, i typed 'dir' by accident and the copy & pasted the error. change the 'dir' to 'dim'

Reply With Quote
  #7  
Old August 5th, 2003, 12:25 AM
allmad allmad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 allmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 sec
Reputation Power: 0
The first bit seems ok now , but now its comeing up with an error ferther down
Attached Images
File Type: jpg error.jpg (43.4 KB, 116 views)

Reply With Quote
  #8  
Old August 5th, 2003, 03:18 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
try removing the quotes around the varindexes

Reply With Quote
  #9  
Old August 5th, 2003, 03:27 AM
allmad allmad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 allmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 sec
Reputation Power: 0
Nope syntax error........

Reply With Quote
  #10  
Old August 5th, 2003, 03:33 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
hmm. let me try this on my excel...

Reply With Quote
  #11  
Old August 5th, 2003, 03:44 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
Yes i see what you mean. Let me shove this to the VB forums.

Reply With Quote
  #12  
Old August 5th, 2003, 01:22 PM
allmad allmad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 17 allmad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 sec
Reputation Power: 0
thanx for your help in this

Reply With Quote
  #13  
Old August 6th, 2003, 09:02 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
To be hones, I didn't really read what you were trying 2 achieve, I'm just fixing Computer's code

Code:
If varindex = 0 Then
    varindex = 1
End If
varindex2 = varindex + 1
Rows(varindex & ":" & varindex).Select
Selection.Insert Shift:=xlDown
rangea = "B" & varindex2
rangeb = "F" & varindex2
Range(rangea & ":" & rangeb).Select
Selection.Copy
rangec = "B" & varindex
Range(rangec).Select
Selection.PasteSpecial Paste:=xlPasteAllExceptBorders, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
varindex = varindex + 2

Remember that you must add 2, bcs a line has already been inserted.

And I just added the if statement, bcs I got an error when I stopped the code, and run it again (bcs varindex = 0)

The rest speaks 4 itself. Shout if you still have a prob.

[edit]
p.s. this is in the onclick event
[/edit]

Reply With Quote
  #14  
Old August 6th, 2003, 10:04 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,673 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 9 h 2 m 19 sec
Reputation Power: 219
Send a message via ICQ to computer
it goes in 'sub commandbutton2_click()' btw and i had an if statement for running the code but didn't paste it in!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > adding to code <