Call Looping Sub

ysffat

New Member
Joined
Mar 25, 2016
Messages
2
Hi All,

Here is my working codes & I am trying to create a sub that can be called from another sub that has different value of (i).

Any one can help on this?

Sub Inv()

Dim i, j As Integer
i = 18
j = i + 2

SendKeys "%{TAB}", True
Application.Wait (Now + TimeValue("00:00:01"))

For i = 18 To j
'Account
ActiveSheet.Cells(i, 12).Copy
SendKeys "^v", True
Application.Wait (Now + TimeValue("00:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("00:00:01"))
'Amount
ActiveSheet.Cells(i, 13).Copy
SendKeys "^v", True
Application.Wait (Now + TimeValue("00:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("00:00:01"))
'Description
ActiveSheet.Cells(i, 14).Copy
SendKeys "^v", True
Application.Wait (Now + TimeValue("00:00:01"))

If j - i <> 0 Then

'Move to Next Line
SendKeys "{DOWN}", True
Application.Wait (Now + TimeValue("00:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("00:00:01"))

End If

Next i

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I am using SendKeys as I could not link this excel with the other application, so I just use copy/paste
 
Upvote 0
Call like this from other sub
VBA Code:
Call Inv(18)

or if the value is in variable x, like this
VBA Code:
Call Inv(x)

Amend first few lines of sub like this

VBA Code:
Sub Inv(i As Integer)
   Dim j As Integer
   j = i + 2
'etc
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top