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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
why are you using SendKeys ?
 

ysffat

New Member
Joined
Mar 25, 2016
Messages
2
I am using SendKeys as I could not link this excel with the other application, so I just use copy/paste
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,281
Messages
5,635,295
Members
416,851
Latest member
zeldadav

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
Top